Mohammad Ali Rony
Mohammad Ali Rony

Reputation: 4905

How to catch error net::ERR_ABORTED

How to catch error net::ERR_ABORTED in ajax. This is my code

$.ajax({
   url: "http://example.com",
   dataType: "jsonp",
   jsonp: "callback",
   timeout: 5000,
   success: function () {
   },
   error: function (xhr, textStatus, errorThrown) {
   }
})

In console I get this error

jquery.js:9679 GET http://example.com/?callback=jQuery33102519970992725571_1523023091094&_=1523023091095 net::ERR_ABORTED

I have tried Try catch but I cannot get any error.is there any way how I can catch this error. I need cross-domain access too. Thanks in advance.

Upvotes: 3

Views: 845

Answers (1)

t3__rry
t3__rry

Reputation: 2849

Hi you could use fail() as such

const request = $.ajax({ //your code })

request.fail((jqXHR, textStatus) => {
  console.log(textStatus);
});

fail in jQuery's docs

Upvotes: 1

Related Questions