我正在向我的 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/