Javascript 如何捕获错误网::ERR_已中止

Javascript 如何捕获错误网::ERR_已中止,javascript,jquery,Javascript,Jquery,如何在ajax中捕获错误net::ERR_。这是我的密码 $.ajax({ url: "http://example.com", dataType: "jsonp", jsonp: "callback", timeout: 5000, success: function () { }, error: function (xhr, textStatus, errorThrown) { } }) 在控制台中,我得到了这个错误 jquery.js:96

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

$.ajax({
   url: "http://example.com",
   dataType: "jsonp",
   jsonp: "callback",
   timeout: 5000,
   success: function () {
   },
   error: function (xhr, textStatus, errorThrown) {
   }
})
在控制台中,我得到了这个错误

jquery.js:9679获取http://example.com/?callback=jQuery33102519970992725571_1523023091094&_=1523023091095 net::ERR_中止


我已经尝试了
Try catch
,但是我没有得到任何错误。有什么方法可以捕捉到这个错误吗。我也需要
跨域访问
。提前谢谢。

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

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

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