gpt4 book ai didi

php - 跟踪 ajax 错误并发出警报

转载 作者:行者123 更新时间:2023-12-01 07:20:42 25 4
gpt4 key购买 nike

我在jquery中使用ajax调用来处理一些数据库操作,在ajax代码中我有一个错误属性警报,它给出了我的错误消息,但我想知道错误是什么?

这是我的ajax代码

    $.ajax(
{
type: "POST",
url: "server/assign_gifts_get_usr_details.php",
data: "",
success: function(xml)
{
alert(xml);
},
error: function()
{
alert("Error, Please try again");
}
});

弹出此警报,alert("错误,请重试");

但我想知道错误。

最佳答案

如果遇到代码的错误部分,则该页面无法正确加载。

这基本上就是错误。

还有一些参数会传递给您也可以使用的错误回调。

See the docs

错误回调获取传入的以下参数:(jqXHR, textStatus, errorThrown)
来自文档:

A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.

关于php - 跟踪 ajax 错误并发出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071319/

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