0

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

Community
  • 1
  • 1
juanefren
  • 2,460
  • 5
  • 28
  • 40

2 Answers2

1
  1. Yes, when you visit a JSON URL, some browsers treat it as text/html, while others treat it as an external file type. You can use an add-on like JSONView.

  2. This should work fine, even though it's redundant. It sounds like a typo. You should also double-check with JSONLint that your JSON document is valid.

Matthew Flaschen
  • 255,933
  • 45
  • 489
  • 528
  • I have already used JSONLint and marks valid, the strange is that I can't use jQuey.getJSON function... I need to use jQuery.ajax without using dataType. – juanefren Apr 06 '11 at 21:42
0

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

juanefren
  • 2,460
  • 5
  • 28
  • 40