开发者

Handling ajax failed response

开发者 https://www.devze.com 2023-02-07 19:41 出处:网络
My error handling isn\'t working on this ajax request... Just now my \"r\" was <br /> <b>Warning</b>:

My error handling isn't working on this ajax request... Just now my "r" was

<br />
<b>Warning</b>:
simplexml_load_string() [
    <a h开发者_开发技巧ref='function.simplexml-load-string'>
        function.simplexml-load-string

and it didn't execute what's in the } else { or even the 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. The PHP error didn't set an HTTP error header, so your AJAX callback read it as a valid response.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消