Skip to content Skip to sidebar Skip to footer

Ajax- Why Do I Get An Error Function Instead Of Success?

I don't understand why is my code running the error function instead of success. I keep getting this from my console.log Object {readyState: 0, getResponseHeader: function, getAll

Solution 1:

If I remember correctly, the success callback is only called if the HTTP return code is 2xx. If you send back a redirection, it is considered as an error.

The documentation mentions it:

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirect), they take the same parameters as the error callback.

From http://api.jquery.com/jquery.ajax/, statusCode section.

Moreover, you have to be careful: if an AJAX request receives a 302 response, it won't do a redirection: that is the user agent of your web browser (classic navigation) that does that automatically, but for XHR/AJAX, you have to implement it.


Post a Comment for "Ajax- Why Do I Get An Error Function Instead Of Success?"