[Fixed]-{Javascript} How to return Json when calling POST xmlHttpRequest

1👍

Django Rest Framwork checks the “Accept” header to define if he must return HTML, JSON, CSV or any other format that he can render (cf: http://www.django-rest-framework.org/api-guide/renderers/)

since you are manually using XMLHttpRequest, try adding the accept header with setRequestHeader. Something like:

xmlHttpRequest.setRequestHeader("Accept","application/json");

check in your console that you are passing the correct headers on Chrome and Firefox

Hope this helps

Leave a comment