curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"latlong": "test"}' http://localhost:8000/geo/api/geolocation/
Quanto sopra funziona bene ma quando provo a replicare il POST nell'ajax in basso ottengo 500 errori.Ajax POST e Django Tastypie
$.ajax({
type: 'POST',
url: 'http://localhost:8000/geo/api/geolocation/',
data: '{"latlong": "test"}',
success: latlongSaved(),
dataType: "application/json",
processData: false,
});
messaggio di errore è:
{"error_message": "The format indicated 'application/x-www-form-urlencoded' had no available deserialization method. Please check your ``formats`` and ``content_types`` on your Serializer." .... }
Degno di nota questo è di dominio croce e sto usando il django-crossdomainxhr-middleware.py trovato tramite git: Gist
Se posso aggiungere un tipo di contenuto per la chiamata AJAX in questo modo:
contentType: "application/json"
ottengo questo errore di nuovo:
XMLHttpRequest cannot load http://localhost:8000/geo/api/geolocation/. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
Request URL:http://localhost:8000/geo/api/geolocation/
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
Access-Control-Request-Headers:Origin, Content-Type, Accept
Access-Control-Request-Method:POST
Origin:http://localhost:3000
Response Headersview source
Access-Control-Allow-Methods:POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin:*
Content-Type:text/html; charset=utf-8
Date:Tue, 23 Aug 2011 07:59:49 GMT
Server:WSGIServer/0.1 Python/2.6.1
Controllare i documenti: potrebbe essere necessario impostare l'opzione JSON nella stringa dell'URL. – Marcin
Puoi pubblicare il diff tra le intestazioni di richiesta 'curl' e le intestazioni jQuery? Puoi vedere le intestazioni jQuery nella scheda della console all'interno di Firebug. –