最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CatchHandle 502 Bad Gateway Error - Stack Overflow

programmeradmin0浏览0评论

I have to update a large collection so I am calling in a loop an web api. I use jQuery.ajax() Something like this:

$.ajax({
   type: 'GET',
    url: '.php',
    jsonpCallback: 'API_SC4',
    contentType: "application/json",
    dataType: 'jsonp',
    data:'action=update&page='+collection[currentIndex].name+'&callback=API_SC4',
    async:false,
    success: function(data) {

        //use data for update of collection[currentIndex]

        UpdateNext(currentIndex+1);
    },
    error: function(e) {
       //interpret error
       UpdateNext(currentIndex+1);
    }
});

The problem is the collection is quite large and sometimes I get a 502 Bad Gateway error and the ajax error handler is not called.

I even tried $( document ).ajaxError() but i'm doing a cross-domain jsonp call , and it seems .ajaxError() does not get called in that situation.

Is there any way to handle that error? Something at window level?
I can see the error in the Chrome development console , and I was thinking there might be a way.

Thanks

I have to update a large collection so I am calling in a loop an web api. I use jQuery.ajax() Something like this:

$.ajax({
   type: 'GET',
    url: 'http://www.somesite./API/API.php',
    jsonpCallback: 'API_SC4',
    contentType: "application/json",
    dataType: 'jsonp',
    data:'action=update&page='+collection[currentIndex].name+'&callback=API_SC4',
    async:false,
    success: function(data) {

        //use data for update of collection[currentIndex]

        UpdateNext(currentIndex+1);
    },
    error: function(e) {
       //interpret error
       UpdateNext(currentIndex+1);
    }
});

The problem is the collection is quite large and sometimes I get a 502 Bad Gateway error and the ajax error handler is not called.

I even tried $( document ).ajaxError() but i'm doing a cross-domain jsonp call , and it seems .ajaxError() does not get called in that situation.

Is there any way to handle that error? Something at window level?
I can see the error in the Chrome development console , and I was thinking there might be a way.

Thanks

Share Improve this question edited Feb 24, 2014 at 12:29 CSchulz 11k11 gold badges62 silver badges117 bronze badges asked Feb 24, 2014 at 12:06 AndreiAndrei 331 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Yes, there is: statusCode. See the jQuery documentation on AJAX for details.

Simple example:

$.ajax({
    statusCode: {
        502: function () {
            alert('Fail!');
        }
    }
});
发布评论

评论列表(0)

  1. 暂无评论