javascript - jquery .then 不会抛出错误
问题描述
使用 $.get promise (jquery 3.3.1) 不会显示任何错误,这使得调试变得不可能
$.get('/').then(function() {
console.log(undef)
})
fetch('/').then(function() {
console.log(undef)
})
第一个例子是静默的,没有抛出错误
第二个示例按预期抛出“Uncaught (in promise) ReferenceError: undef is not defined”
它是一个 jquery 错误还是我以错误的方式使用它?您如何建议使用 fetch 代替?我担心浏览器的兼容性
解决方案
您可以在链中添加失败功能:
$.get('/').then(function() {
console.log(undef);
})
.fail(function(){
console.log("Error");
})
推荐阅读
- python - python - 如何在python中将一对空格分隔为文本文件?
- java - 登录后执行 ConstraintSet 后按钮不可见
- reactjs - 如何在 React 应用程序中包含 PHP 代码 - 没有 ajax
- azure - Azure DevOps 授予对管道的存储库访问权限
- java - Firebase 本身增加 Long 值
- prolog - 列出宽度为 1 的窗口
- flutter - 在 Flutter 中扩展材质组件
- javascript - 如何将 HTML 元素与 JavaScript 中的一行连接起来?
- c - 子进程池
- javascript - MediaSource 画布到带音频的视频转换