I have a form that is being serialized by JQuery and posted via .ajax() to a url.
The problem is that the 'success:' function is always called, regardless of whether the server returns an error code or not.
In fact, success fires even before the server has responded (I have put a breakpoint on the server method that services the request - success fires even before this method is completed). If the server returns an error code (e.g. Status code 500) JQuery calls BOTH success and error events!
Any ideas what's going on? Here's my jquery code:
$("#a-dialog").dialog({
autoOpen: false,
height: 300,
width: 400,
modal: true,
buttons: {
"Submit": function() {
$.ajax({
type: 'POST',
url: theURL,
data: $("#a-dialog-form").serialize(),
success: alert('ok!') // THIS IS ALWAYS CALLED (IMMEDIATELY)
});
},
},
});
UPDATE:
This was a stupid error on my part! Thanks to blue112 for quickly pointing it out :)
That's normal, you must pass it as a callback, eg
$.ajax({
type: 'POST',
url: theURL,
data: $("#a-dialog-form").serialize(),
success: function(){alert('ok!');} // The function will be called upon success.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With