如何在 jQuery 的 load() 方法中捕获错误 [英] How to catch error in jQuery's load() method
本文介绍了如何在 jQuery 的 load() 方法中捕获错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 jQuery 的 .load()
方法在用户单击按钮时检索一些数据.
加载成功完成后,我将结果显示在
中.
问题是,有时在检索数据时 load()
中会发生错误.
如何在 load()
中捕获错误?
解决方案
关于加载错误如何发生的一点背景......
$("body").load("/someotherpath/feedsx.pxhp", {limit: 25},函数(响应文本,文本状态,请求){如果(文本状态==错误"){返回哦,不!!!!";}});
添加了注释要求的根路径以外的路径.
I'm using jQuery's .load()
method to retrieve some data when a user clicks on a button.
After the load successfully finishes, I show the result in a <div>
.
The problem is, sometimes an error occurs in load()
while retrieving the data.
How can I catch an error in load()
?
解决方案
Just a little background on how a load error happens...
$("body").load("/someotherpath/feedsx.pxhp", {limit: 25},
function (responseText, textStatus, req) {
if (textStatus == "error") {
return "oh noes!!!!";
}
});
Edit: Added a path other than the root path as requested by comments.
这篇关于如何在 jQuery 的 load() 方法中捕获错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文