gpt4 book ai didi

php - 如何获取 jQuery $.ajax 错误响应文本?

转载 作者:IT老高 更新时间:2023-10-28 11:39:37 26 4
gpt4 key购买 nike

我正在向我的 jQuery 发送错误响应。但是,我无法获得响应文本(在下面的示例中,这将是 Gone to the beach)

jQuery 唯一说的是“错误”。

详情请看这个例子:

php

<?
header('HTTP/1.1 500 Internal Server Error');
print "Gone to the beach"
?>

jQuery

$.ajax({
type: "post",
data: {id: 0},
cache: false,
url: "doIt.php",
dataType: "text",
error: function (request, error) {
console.log(arguments);
alert(" Can't do because: " + error);
},
success: function () {
alert(" Done ! ");
}
});

现在我的结果是:

日志:

 [XMLHttpRequest readyState=4 status=500, "error", undefined]

警告:

Can't do because: error

有什么想法吗?

最佳答案

试试:

error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}

关于php - 如何获取 jQuery $.ajax 错误响应文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637019/

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