Best way to check if AJAX request was successful in jQuery?

By calling $. Post that way, you automatically pass only in a success handler function If something on the request went wrong, this method is not even executed To have more control either use $.ajax() directly, or pass in fail handlers. That could look like $.

Post("page. Php", {data: stuff}, function(data, status) { // we're fine here }). Fail(function(err, status) { // something went wrong, check err and status }) The same thing using ajax() : $.

Ajax({ type: 'POST', url: 'page. Php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' }) You can even pass more ajax event handler to $. Ajax like beforeSend to modify/read XHR headers or complete to have a handler which fires either way (error or not) when the requests finished.

By calling $. Post that way, you automatically pass only in a success handler function. If something on the request went wrong, this method is not even executed.To have more control either use $.ajax() directly, or pass in fail handlers.

That could look like $. Post("page. Php", {data: stuff}, function(data, status) { // we're fine here }).

Fail(function(err, status) { // something went wrong, check err and status }); The same thing using .ajax(): $. Ajax({ type: 'POST', url: 'page. Php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' }); You can even pass more ajax event handler to $.

Ajax, like beforeSend to modify/read XHR headers or complete to have a handler which fires either way (error or not) when the requests finished.

JQuery considers "successful" in the way it is in the source code, of course. This does not include a status code of 404/500 and neither a timeout, since no status code has been returned in that case. You can check when exactly it returns "success": // If successful, handle type chaining if ( status >= 200 && status.

I prefer to use the ajax call, as it has an explicit success handler $. Ajax({ url: "page. Php", data: stuff, success: function(response){ console.

Log("success"); } }); I'd also recommend using firebug or webkit similar, then you can track the requests and check the parameters!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions