11th May, 2009 Hi Dave, I am facing a peculiar problem using jQuery AJAX with ASP.NET and would like you to look into it. I am using Generic Handlers for writing my server side code and making AJAX calls using jQuery. On the server side, I am using JayRock for creating JSON objects. The problem is, when I make a POST call using $.ajax, I am not able to retrieve parameters in the handler [using Request.form()]. But if I make a POST call using $.post, I am able to retrieve the parameters (Note that I did not make any server side code change. Just changed client side implementation from $.ajax to $.post). I am not able to understand where I am going wrong. Can you please help me? Here is my code: http://labs.novogeek.com/Doubts/complextypes.txt Regards, Krishna ******************************************************************************* Hi, Krishna. Your $.post implementation is okay in this case. The only time that the more complex $.ajax implementation is necessary is when calling ASP.NET AJAX serialized ASMX services and page methods. Since you're handling all that yourself in the ASHX, you don't have to worry about setting the content-type or data type on the request. With that in mind, the $.post shortcut is basically the exact same $.ajax call with less verbose options. That said, I believe you could make the $.ajax version work if you change your data parameter to just: data: { 'fname' : $('#txtFirstName').val() } That will POST it to the server in normal k,v form of fname=value, instead of sending the JSON string. Then, it will be accessible in Request.Form("fname") as desired. Dave ******************************************************************************* ******************************************************************************* 21st May, 2009 Hi Dave, Since I don't want to use ASP.NET AJAX in my project for various reasons, I am using JayRock for JSON RPC and deserialization. I made a very simple demo on passing complex types with DTO, but using JayRock instead of ASP.NET AJAX. Can you please review it and let me know where I can improve? Here is the working demo: http://labs.novogeek.net/complextypes/default.aspx ******************************************************************************* Hi, Krishna. If it were me, I would probably clean up the "data" parameter. You can build the entire object first and then stringify it. Something like: var d = { }; d.id = 1; d.method = 'fnAjaxMethod'; d.params = { }; $(':text').each(function() { d.params[this.name] = this.value; }); Then, you can just use d as the "data" parameter. I find that easier to maintain, instead of hard coding the values into the "data" string. That would bring the params object up one level too, instead of pushing it into "obj". I'm not sure if you were doing that on purpose for another reason, but it's not necessary in this example. The JSON would become this: {'id':'1','method':'fnAjaxMethod','params':{'FirstName':'Dave','LastName':'Ward'}} Instead of this: {'id':'1','method':'fnAjaxMethod','params':{'obj':{'FirstName':'Dave','LastName':'Ward'}}} Hope that helps, Dave