javascript - 当通常的错误字段为空时,我们还能找到更多关于 jQuery .ajax() 失败的原因?
问题描述
var request = $.ajax({
url: url,
method: "POST",
dataType: "json",
timeout: 5000,
error: function (jqXHR, exception, errorThrown) {
// in the case which I am trying to debug ...
console.log(jqXHR.status);
// Outputs a 0 - not useful, general purpose 'network is down' and 3 other reasons
console.log(jqXHR.statusText);
// Outputs "error" - not useful
console.log(jqXHR.responseText);
// Outputs "undefined" - not useful
console.log(exception);
// Outputs "error" - not useful
console.log(errorThrown);
// Outputs "" - not useful
});
有什么方法可以获取更多关于出了什么问题的信息?
When jqXHR.status
is 0
,这意味着主机无法访问,但问题是,它正在连接到它在几毫秒前获取 Javascript 的完全相同的主机(在相同的https
协议上),所以它真的不太可能关闭 - 别的发生了。
谢谢大家,注意安全。
编辑:
- 我的问题是问如何以编程方式找出答案;打开开发者控制台不是一种选择。
- 我已正确设置 CORS 标头。这个 Ajax 调用在 1000 次中有 998 次有效。
解决方案
推荐阅读
- ios - 如何从 App Store Connect 中删除应用程序?我有错误
- api - 我无法通过 rest() 组件到达 openshift 中的端点
- phpmyadmin - phpMyAdmin 密码是否可以与 cPanel 不同
- react-native - React-Native (expo) 检索初始主题(或任何初始化值)
- python - 类型错误:+ 不支持的操作数类型:“int”和“NoneType”
- reactjs - React - 最新版本或最新依赖项版本不喜欢文件路径中的撇号
- api - 如何通过 API 将新的销售订单和订单项发布到 Business Central?
- flutter - 空安全和地图
- javascript - 如何使用 Ajax 从 ASP.net MVC 中的 DataTable 导出 CSV 文件?
- android - getItemViewType() 中的 RecyclerView 位置始终为 0