gpt4 book ai didi

javascript - 如何捕获错误 net::ERR_ABORTED

转载 作者:行者123 更新时间:2023-11-29 23:24:33 32 4
gpt4 key购买 nike

如何在 ajax 中捕获错误 net::ERR_ABORTED。这是我的代码

$.ajax({
url: "http://example.com",
dataType: "jsonp",
jsonp: "callback",
timeout: 5000,
success: function () {
},
error: function (xhr, textStatus, errorThrown) {
}
})

在控制台我得到这个错误

jquery.js:9679 GET http://example.com/?callback=jQuery33102519970992725571_1523023091094&_=1523023091095 net::ERR_ABORTED

我试过 Try catch 但我没有得到任何错误。有什么方法可以捕获这个错误。我也需要跨域访问。提前致谢。

最佳答案

你好,你可以这样使用fail()

const request = $.ajax({ //your code })

request.fail((jqXHR, textStatus) => {
console.log(textStatus);
});

fail in jQuery's docs

关于javascript - 如何捕获错误 net::ERR_ABORTED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49694794/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com