什么问题可能使用MIME类型应用程序/ json原因? [英] What problems may using the MIME type application/json cause?

查看:371
本文介绍了什么问题可能使用MIME类型应用程序/ json原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个Web服务需要返回JSON数据。 我读了应该使用application / json ,但不知道这可能导致什么问题?



例如,旧版浏览器是否支持? (IE6 +,FF,Opera等)



或者,公司防火墙/代理服务器背后的用户是否可能阻止MIME类型应用程序/ json?

$

解决方案

让我们考虑一下IE。假设您有一个隐藏的iFrame,您可以使用它来请求文件下载。例如

 < iframe src =getFile?id = 123> 

现在,服务器可能会发送一个JSON编码的错误消息,例如

  {
错误:'文件123不存在',
retryLater:false
}

如果该错误消息以 application / json 形式发送,



另一方面,MIME类型 text / plain 会导致消息在iFrame中呈现,您可以提取它,并使用JScript将其转换为一个花哨的弹出窗口或其他东西。






(编辑)



现实世界示例: EXTJS Fileupload - IE8安全栏问题


I am working on a web service the needs to return JSON data. I read that I should use application/json but am not sure what problems this may cause?

For example, will older browsers support it? (IE6+, FF, Opera, etc.)

Or is it possible that users behind corporate firewalls/proxy servers block the mime type application/json?

What, if any, problems have you had following this advice?

解决方案

Let's consider IE. Say you have a hidden iFrame which you use to request a file download. For example

<iframe src="getFile?id=123">

Now, the server may send a JSON-encoded error message like

{
    error: 'File 123 does not exist',
    retryLater: false
}

If that error message is sent as application/json, a download dialog will appear, because the JSON text is mistaken for the actual file.

On the other hand, a MIME type of text/plain will cause the message to be rendered in the iFrame, and you can extract it, and transform it into a fancy pop-up or something using JScript.


(Edit)

Real-world example: EXTJS Fileupload - Problem with IE8 security bar

这篇关于什么问题可能使用MIME类型应用程序/ json原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆