curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"latlong": "test"}' http://localhost:8000/geo/api/geolocation/
This works fine, but when I try to reproduce the POST in ajax below, I get 500 errors.
$.ajax({ type: 'POST', url: 'http://localhost:8000/geo/api/geolocation/', data: '{"latlong": "test"}', success: latlongSaved(), dataType: "application/json", processData: false, });
Error message:
{"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." .... }
It is worth noting that this is a cross-domain, and I am using django-crossdomainxhr-middleware.py found using git: gist
If I add a content type to an ajax call, for example:
contentType: "application/json"
I am returning this error:
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
jquery ajax django tastypie
Rob b
source share