【发布时间】:2010-12-10 20:33:25
【问题描述】:
我正在向我的 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]
警告:
不能这样做,因为:错误
有什么想法吗?
【问题讨论】:
-
问题似乎出在您的 php 代码中。标题和正文之间不需要 2 个换行符吗?
header函数能处理这个吗? -
thenduks:PHP 知道它在做什么。问题是因为返回的 HTTP 状态是 500,
$.ajax()调用了传递给它的错误函数。
标签: php javascript jquery ajax error-handling