gpt4 book ai didi

javascript - jquery错误函数帮助

转载 作者:行者123 更新时间:2023-11-29 15:50:46 25 4
gpt4 key购买 nike

我不太喜欢 javascript,但我想在我正在从事的这个项目中实现错误对话框。我想发送一个 http header ,错误函数将捕获该 header 并显示正确的消息。我已经用警告框测试了错误函数,当我发送 header 400 时,错误函数被触发。

是否可以在 JQuery 或 javascript 中根据 header 代码(如 400 或 401)显示不同的消息/对话框?基于该代码然后向用户显示正确的错误消息?我需要为每个错误函数显示大约 4 或 5 条消息

error:function(){
// call my dialog here
}

最佳答案

statusCode 选项在 jQuery 1.5+ 中可用 jQuery.ajax :

A map of numeric HTTP codes and functions to be called when the response has the corresponding code. For example, the following will alert when the response status is a 404:

$.ajax({
statusCode: {
404: function() {
alert('page not found');
}
}
});

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error, they take the same parameters as the error callback.

关于javascript - jquery错误函数帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5750246/

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