Django Ajax Body To Json

django ajax body to json
# In Django you need to deserialize the json

import json
def my_view(request):
body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
content = body['content']
django ajax body to json
// From AJAX you need to post the data as JSON string rather than
// a JavaScript object.
payload = JSON.stringify({"name": "foo", "username":"bar"})

$.ajax({
url: 'some url',
type: "POST",
// ...
data: payload,
dataType: 'json',
//..
})

Leave a Comment