weixin_33670713 2011-04-06 21:21 采纳率: 0%
浏览 78

不正确的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

  • 写回答

2条回答 默认 最新

  • 三生石@ 2011-04-06 21:26
    关注
    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容