jquery ajax ignores 500 status error

前端 未结 3 2028
情歌与酒
情歌与酒 2020-12-10 13:02

I\'m making some GET requests to an App Engine app, testing in Chrome. Whilst I can see in javascript console that some calls result in a 500 server error, I can\'t seem to

3条回答
  •  余生分开走
    2020-12-10 13:16

    I had a similar problem, I was using jquery's promise functions of .done, .fail, .always, and if I encountered a 500 internal server error then it would not fire any of the functions (done, fail, always, error). very weird.

    in the end I added a timeout into the .ajax options, when it hits the timeout it throws an error and also runs the .fail method.

    searchify.myAjaxSearchTerms = $.ajax({
                            'url': url,
                            type: "GET",
                            'dataType': 'jsonp',
                            'jsonp': 'json.wrf',
                            'jsonpCallback': searchify.cbFunc,
                            timeout: 4000, //needed for 500 errors - will go to fail block on timeout
                            beforeSend: searchify.beforeSendAutocomplete
    
                        });
    searchify.myAjaxSearchTerms.fail(function(XHR, status, error){
                            searchify.clearForm();
                            searchify.renderWarningForNoQuery('
    Sorry. We had a problem performing that search...
    Please try again
    Enter a product name, catalogue number or keyword
    '); });

提交回复
热议问题