[Fixed]-Django + Ajax error in returning data

1👍

Your form is almost certainly invalid; you’re returning a 400 status in that case from form_invalid, which triggers jQuery to call the failure function if there is one, rather than success.

Unfortunately, you can’t use proper RESTful status codes in this kind of situation. An invalid form submission should still return a 200.

0👍

There is a difference between success and complete function of the ajax function that you are using…

success

It gets called on a response of 200 (OK).

complete

This will get called always , well as the name suggests the request did succeed, even if was a failure on the server side or OK response. It just succeeded (ie: landed your server and brought something back to offer to your client(browser,mobile whatever).So that’s complete method for.

You can do away with this method and can use only success if not needed otherwise.

For more info. Read here

FYI :

The readystate output you showed says 0 , hence the request isn’t initialized.It should be 4 for the request to be complete.

Leave a comment