Tuesday, 15 February 2011

jquery - Ajax, when response has some value i want to treat it as an ajax error -



jquery - Ajax, when response has some value i want to treat it as an ajax error -

whats happening , working on big application, way team handles server side errors send json response error=true (its still 200 success) (its hard me alter send different status codes), , in ajax success phone call same function alert using dialog error message if error=true else execute normal logic,

what want utilize single ajax event hook in before success happens , check first if value has error=true don't phone call success handler , show dialog

you alter construction of success , error handlers run same code if error=true.

for illustration do:

$.ajax( success: function(data){ if (data.error){ runerrorcode(); return; } //success code... }, error: function(){ runerrorcode(); }); function runerrorcode(){ alert("an error has occurred"); }

jquery ajax

No comments:

Post a Comment