gpt4 book ai didi

javascript - jquery .then 不会抛出错误

转载 作者:行者123 更新时间:2023-12-01 02:27:05 26 4
gpt4 key购买 nike

使用 $.get Promise (jquery 3.3.1) 不会显示任何错误,这使得调试变得不可能

$.get('/').then(function() {
console.log(undef)
})

fetch('/').then(function() {
console.log(undef)
})

第一个示例是静默的,没有抛出错误

第二个示例按预期抛出“未捕获(在 promise 中)ReferenceError:undef 未定义”

这是一个 jquery 错误还是我以错误的方式使用它?您建议如何使用 fetch 来代替?我担心浏览器兼容性

最佳答案

您可以在链中添加失败函数:

$.get('/').then(function() {
console.log(undef);
})
.fail(function(){
console.log("Error");
})

Reference

关于javascript - jquery .then 不会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61345266/

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