how to catch ajax query post error?
Posted
by TTCG
on Stack Overflow
See other posts from Stack Overflow
or by TTCG
Published on 2010-05-14T12:07:35Z
Indexed on
2010/05/14
12:14 UTC
Read the original article
Hit count: 479
I would like to catch the error and show the appropriate message if the ajax request fails. My code is like the following, but I could not manage to catch the failure ajax request.
function getAjaxData(id)
{
$.post("status.ajax.php", {deviceId : id}, function(data){
var tab1;
if (data.length>0) {
tab1 = data;
}
else {
tab1 = "Error in Ajax";
}
return tab1;
});
}
I found out that, "Error in Ajax" is never executed when the Ajax request failed. How to handle the ajax error and show the appropriate message if it fails? Thanks very much.
© Stack Overflow or respective owner