jQuery.post()失败回调函数? [英] jQuery.post() failure callback function?
本文介绍了jQuery.post()失败回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个代码:
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});
有没有办法检查请求是否失败(例如由于超时)?
Is there any way to check if the request have failed (e.g. due to the timeout)?
推荐答案
是的,来自 jQuery文档:
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
})
.fail(function() {
alert("error");
})
更新:drake7077:从jquery 1.8开始不推荐使用错误,请使用.fail()
Update: drake7077: "error is deprecated as of jquery 1.8, use .fail()"
这篇关于jQuery.post()失败回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文