What a sad alphabet soup of acronyms this post has for a title…
Just a quick note on using Json ajax requests with asp.net mvc 3.
Adding a hnadler for a json request to a controller is easy, the return type is just JsonResult, and the controller’s Json method will handle the serialisation of the data.
The only gotcha is that by default, get will be disabled for json requests.
If you want to use the method withoutchanging that default, you cant use $.getJson, you need to use $.post instead.
$.post("<url>",
"<data>,
function (data,ststus,jqxhr) {
/*handle the result*/
},
"json");
It is worth remembering that you can use the “Promise” interface from jquery 1.5 on to add an error handler, or it fails silently:
$.post("<url>",
"<data>,
function (data,ststus,jqxhr) {
/*handle the result*/
},
"json").error(function(){/*error alert*/});
and if you need to parcel up the form for the data use $(“form selector”).serialize();