1

I have tried the functionality of error logging with the ajaxError.

Its working perfectly well but it does not work with cross domain.

$(document).ready(function(){
    $(document).ajaxError(function(event,request,settings){
      console.log('error');
});
});

Is there a way to log errors for the AJAX API calls for cross domain(https) , in similar way as above ?

Amir
  • 73
  • 5
  • 1
    Maybe this post is helpful for you: https://stackoverflow.com/questions/19035557/jsonp-request-error-handling/19185826#19185826 – Exos Aug 11 '15 at 05:32

1 Answers1

1

[jQuery documentation] mentioned that ajaxError does not work with cross-domain scripts.

I would rather use jqXHR.fail() to do error handling per ajax call, unless you have too many APIs to call.

$.get('https://another.domain.com/api/data.json', function() {
    console.log('success');
}).fail(function() {
    console.log('error');
});
charlee
  • 1,309
  • 1
  • 11
  • 22
  • Thanks for the answer. I need to make a monitoring javascript which monitors my frontend ajax calls. If any error occurs it gets logged in file. Is it feasible to use such jqXHR.fail() for monitoring purpose ? – Amir Aug 11 '15 at 05:34
  • it depends on how many ajax calls you have... say, if you have only a few ajax calls you can simply add `.fail()` to all your ajax calls and call a common error logging function inside it...otherwise if you have thousands of ajax calls (which is not likely the case) you have to fix too much code which is difficult from the perspective of source code management. – charlee Aug 11 '15 at 05:38