I’m trying to post some data through jQuery AJAX to a Django (1.4) view. I’ve done this before, but something isn’t right this time around. I’ve done my AJAX set up to include the CSFR token as explained in the Django Docs.
jQuery along the lines of:
$.ajax({
url:'/login/',
type:'POST',
contentType:'application/json; charset=UTF-8;',
dataType:'json',
data: JSON.stringify({
username:$('#this').val(),
password:$('#that').val()
})
However, when I send the data, when I include the line in the view:
print request.raw_post_data
it will print twice. The first time with the posted data as a QueryDict {u’this’:u’these’, u’that’:u’those’}, and the second time with csrfmiddleware token.
Why is printing two times? Shouldn’t they be in the same QueryDic?
Because I had not included
the form was sending twice. One QueryDict was valid but the view function didn’t process b/c the default submit data only had the csrftoken.
Used
to get my data.