[Django]-JQuery and django-rest-framework-bulk: send list

12๐Ÿ‘

โœ…

If you look into request header, you will notice:

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

This is incorrect type for json data.

You need to set the correct content type and serialize the data:

$.ajax({
    type: "POST",
    url: "/api/articles/",
    data: JSON.stringify(data),
    sucess: function() { console.log("Success!"); },
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    crossDomain:false,
    beforeSend: function(xhr, settings) {
      xhr.setRequestHeader("X-CSRFToken", csrftoken);
    }
});
๐Ÿ‘คmariodev

Leave a comment