“Django Ajax Cuerpo a JSON” Código de respuesta

Django Ajax Cuerpo a 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 Cuerpo a 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

Respuestas similares a “Django Ajax Cuerpo a JSON”

Preguntas similares a “Django Ajax Cuerpo a JSON”

Más respuestas relacionadas con “Django Ajax Cuerpo a JSON” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código