yceruto/django-ajax

Getting 400 request error!

Closed this issue · 4 comments

When I use AJAXMixin in class base view I got 400 request error with message in console
Bad Request

Hi @9iaashalaby I will need more details about your error, like a tracelog or how to reproduce it.

I just re-build the tests and it seems to be ok on my side, https://travis-ci.com/github/yceruto/django-ajax/builds/232315719

Please provide more information, it might not be related to this package.

Same problem for me. 400 error. So I just implemented the ajax view w/o the decorator.

django>=3.2.8
whitenoise[brotli]>=5.3.0
psycopg2-binary>=2.9.1

I am not using jQuery. That might make a difference?

// async remove
  var request = new XMLHttpRequest();
  var url = "{% url 'ajax-remove-from-wishlist' %}";
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type", "application/json");
  request.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
  request.onreadystatechange = function () {
      if (request.readyState === 4 && request.status === 200) {
          var jsonData = JSON.parse(request.response);
          console.log(jsonData);
      }
  };

  var data = JSON.stringify({
      'property-id': this.id
  })

  console.log(data);

  request.send(data);