Cause 1: AJAX Call Cancelled by a Reload or Redirect
This occurs when the AJAX call is triggered at the same time as a browser event that reloads or redirects the page. This causes a race condition where the AJAX call is started but the browser event navigates away from the current page before the call’s completion. This causes the AJAX request to be canceled with the “0” error message.
Triggering events could include the following:
Clicking on a link
The solution to this depends on how your code is triggering the AJAX call and any other simultaneous events. Generally, make sure of two things:
If you prompt the AJAX call via a trigger with a default event that causes the page to redirect/reload, make sure to override the default behavior and have the event wait until the AJAX call is complete before redirecting. Add this behavior back into the AJAX completion handler function as per #2.
If you need to perform any other logic related to reloading/redirecting the page, make sure to add this logic inside the AJAX completion handler. Otherwise, restructure your code so it doesn’t perform this action until the AJAX call is complete.
Cause 2: Cross-Domain Issues
This occurs when the AJAX function call tries to make a cross-origin request and is blocked by the browser. This is usually easy to diagnose as if it exists, it will cause the AJAX call in the function to fail every time. The error occurs because due to browser security controls, most AJAX requests are subject to same origin policy. For solutions, this Stack Overflow Reference has some potential leads. Alternatively, try enabling CORS or making a request via JSONP.