“Django Ajax Body an JSON” Code-Antworten

Django Ajax Body an 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']
          
Lovely Coder

Django Ajax Body an 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',
  //..
})
Lovely Coder

Ähnliche Antworten wie “Django Ajax Body an JSON”

Fragen ähnlich wie “Django Ajax Body an JSON”

Weitere verwandte Antworten zu “Django Ajax Body an JSON” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen