What is AJAX Call Error in Javascript and How Can You Troubleshoot It? 

AJAX call error in Javascript

This article aims to help you diagnose and investigate the Javascript AJAX call error response below. This error occurs when making an AJAX call, and may have multiple causes. However, the error is often due to one of two primary causes.

{readyState:0,status:0,statusText: error}

Investigating the Javascript AJAX Call Error

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:

  • Form submission

  • 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:

  1. 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.

  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.


Share Post:

Stay Connected

More Updates

Deliver better eCommerce experiences.
Prevent revenue loss.

Get Your Free Checkout Audit!

Contact Sales Specialist

Get a Free Site Audit!

Contact Sales Specialist

Get a Demo