JQuery ajax ($.ajax()) returning to error function despite success (200 ok) response

Posted by

Turns out that returning void from (asp.net mvc) server function, but jquery ajax call data type was set to json – so when receiving no data back – the ajax function returns to the error function.

So the example below would always alert “error” as the server controller action return was void

$.ajax({type: “POST”,url: “/MyController/MyAction/”,data: [postData], success: function (data) { alert(“success”); }, error: function () { alert(“error”); } });

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s