0

I have an AJAX call as follows:

    $.ajax({
        type: "get",
        url: "xxx.xxx.xxx/xxx.js",
        dataType: 'jsonp',
        success: function(data) {
            console.log("success");
        }
    }).done(function(data){
        console.log("done");
    }).fail(function(data){
        console.log("fail");
    }).always(function(){
        console.log("always")
    });

When the call succeeds, the success and done functions run. However, when the call fails (like when I change the url to gobbledygook) nothing runs, not even always.

The behavior happens in both Firefox and Chrome.

I've seen a number of other people mention that it's a problem with JSONP, and the accepted answer says that making it async: false would work, but neither async: false nor async: true worked.

What seems to be the issue here?

abustamam
  • 1,597
  • 2
  • 13
  • 21

1 Answers1

0

A workaround that worked is adding a timeout.

$.ajax({
    type: "get",
    url: "xxx.xxx.xxx/xxx.js",
    dataType: 'jsonp',
    success: function(data) {
        console.log("success");
    },
    timeout: 5000
}).done(function(data){
    console.log("done");
}).fail(function(data){
    console.log("fail");
}).always(function(){
    console.log("always")
});

Then after 5 seconds, the error/always works.

abustamam
  • 1,597
  • 2
  • 13
  • 21