[Fixed]-Django ajax javascript not working

1👍

There are multiple issues that could be causing this behavior:

  1. You are submitting your form, therefore reloading the page. The ajax1() function should return false to prevent the browser from automaticly sending the form.
  2. The url that is used in xhr.open() is not the same as the url defined in urls.py
  3. I’m not sure what causes the broken pipe error. It might be the mimetype. application/javascript is used for sending actual Javascript code to the browser. The mimetype that you need for sending text (like with AJAX) is text/plain. In your case there is no need for defining the mimetype at all.

Leave a comment