Search code examples
jqueryajaxdjangojsonsimplejson

incorrect json mimetype?


I have followed this How do I JSON serialize a Python dictionary? and this What is the correct JSON content type? to create a json response like this:

def json_response(something):
    return HttpResponse(
        simplejson.dumps(something),
        content_type = 'application/json; charset=utf8'
    )

How ever I have two complains:

a) When I hit my ajax URL directly in Google Chrome, Inspector says

Resource interpreted as Document but transferred with MIME type application/json.

also tried Firefox and it gets as a file to download.

b) When I use jQuery.ajax works only if I don't pass the dataType argument, if I put for example dataType:'json' then I get this error on jquery.js file

Uncaught SyntaxError: Unexpected token :

What am I doing bad?

I am using jquery 1.5.2 and Django Trunk (r15915 updated about two weeks ago) and calling only same domain urls.

EDIT: jQuery.getJSON does not work, but worked on jquery 1.4.2. Looking firebug console on Request Headers says Content-Type: application/x-www-form-urlencode, this may be related to the problem.

Thanks in advance


Solution

  • There was a bug with jquery validate plugin, updating to most recent version solved the problem.

    More info about the issue here: https://forum.jquery.com/topic/getjson-and-jquery-1-5