[英]Handling ajax failed response
My error handling isn't working on this ajax request... Just now my "r" was 我的错误处理不适用于此Ajax请求...刚才我的“ r”是
<br />
<b>Warning</b>:
simplexml_load_string() [
<a href='function.simplexml-load-string'>
function.simplexml-load-string
and it didn't execute what's in the } else {
or even the console.log 并且它没有执行
} else {
甚至console.log中的内容
success: function (r) {
console.log(r);
$('.processing').addClass('hide');
if (r.type == 'success') {
if (r.message.match(/approved/).length > 0) {
triggerNotification('check', 'Payment has been accepted');
} else {
triggerNotification('check', r.message);
}
document.location = '/store/order/view?hash='+r.hash;
} else {
$('.button').show();
var msg = 'Unable to run credit card: '+r.message;
if (parseInt(r.code) > 0) {
msg = msg+' (Error code: #'+r.code+')';
}
triggerNotification('x', msg);
}
},
That's a PHP error, not an AJAX error. 那是PHP错误,而不是AJAX错误。 The PHP error didn't set an HTTP error header, so your AJAX callback read it as a valid response.
PHP错误未设置HTTP错误标头,因此您的AJAX回调将其读取为有效响应。
It also seems that you are using dataType: json
, so since the response from PHP was HTML and not JSON, r
would be undefined
and that's why console.log(r)
failed (which probably threw an error in your console, and killed the script). 似乎您也使用的是
dataType: json
,因此由于PHP的响应是HTML而不是JSON,因此r
将是undefined
,这就是为什么console.log(r)
失败的原因(这可能在您的控制台中引发错误,并杀死了脚本)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.