Fuad Hirad
0
Q:

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']
          
0
// 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',
  //..
})
0

New to Communities?

Join the community