json xhr 响应打开下载文件弹出窗口
对于我们的一个 ajax 请求(带有 .json 响应),我们的一些客户抱怨他们看到“文件下载”提示,要求用户下载 .json 响应。 我很困惑,因为考虑到这是 xhr 响应,这种情况永远不应该发生。 有人见过这个吗?
谢谢
For one of our ajax request (with a .json response) some of our clients have complained that they are seeing a "File Download" prompt asking the user to download the .json response. I am baffled because considering that this is an xhr response, this should never happen. Has anyone seen this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我正在使用QQ ajax文件上传器,我发现我需要将内容类型设置为“text/json”才能正常工作。
I am using the QQ ajax file uploader and I found that I needed to set the content type to "text/json" for it to work properly.
删除 .json 并将内容类型设置为 text/html。 IE 不知道您发送的文件类型,因此它会提供下载。 它知道如何处理 text/html :)
Drop the .json and set the content type as text/html. IE doesn't know what type of file you are sending it, so it offers to download. It knows what to do with text/html :)
对于使用 ASP MVC 并且在 IE 上遇到同样问题的人,在返回响应时使用此:
编辑:标准类型是:“application/json”,但不适用于 IE。 使用 text/html 是危险的。
For people who are using ASP MVC and have the same problem with IE, use this when returning your response:
Edit: the standard type is: "application/json", but does not work with IE. using text/html is dangerous.
尝试在响应中指定“text/plain”的 MIME 类型。 或者只是从 URL 中删除“.json”扩展名(例如,尝试使用 .txt 或 .js)
try specifying a MIME type of "text/plain" in the response. or just drop the ".json" extension from the url (try .txt, or .js, for instance)
不确定您是否找到了解决方案,但我遇到了类似的问题,IE 尝试下载任何 JS 响应。 为了解决这个问题,我必须确保 format.html 出现在响应块中的 format.js 之上:
希望这会有所帮助。
Not sure if you found a solution, but I had a similar problem where IE tried to download any JS responses. To fix it, I had to ensure that format.html appears above format.js in the response block:
Hope this helps.