360SDN.COM

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

来源:  2017-06-22 13:23:06    评论:0点击:

来源:http://blog.csdn.net/u013009809/article/details/53172675

今天发布一个项目的时候,遇到了一个奇怪的问题,一个后台管理系统的excel导出。在我的本地测试中,导出没有任何问题,但是发布到服务器之后,第一次导出没有问题,多次导出之后,浏览器直接白屏。从服务器后端找错误,被其他无关的错误所误导。最终,在浏览器的调试中发现了这样一句话:Resource interpreted as Document but transferred with MIME type applic。。。, 网上搜索了一下,找到了一条英文的答案,如下:

 

Dear Dimitar,

Thanks for the quick answer, I should defenitely check SO before posting here, sorry for that. The first link was sort of helpful but rather incomplete I’m afraid.

The good news is that there is a solution that worked for me: to change the server response MIME to text/htmlargs.event.response is then a string containing the JSON; I can parse it. However I’m fortunate enough to have control over the server process, that might not be a suitable solution in everey case.

Another proposed solution was to remove multipart/form-data, but this is not possible when uploading files.

Another one wat to add a query string to the URL, didn’t work for me (I was suspicious about this solution anyway).

Finally, apparently, the definite solution is to use $.post instead of ajaxSubmit. However I suspect this call is buried somewhere in jqxfileupload.js or jQuery-1.11.1.min.js.

Here’s the stack trace I get from Chromium, if it is of any value:

Resource interpreted as Document but transferred with MIME type application/json: “http://localhost:8080/…”.
a.extend._uploadFile @ jqxfileupload.js:7
(anonymous function) @ jqxfileupload.js:7
m.event.dispatch @ jquery-1.11.1.min.js:3
r.handle @ jquery-1.11.1.min.js:3

Thank you very much, jqxWidgets is fantastic,
Robert

大概意思是:这个罗伯特对这个问题有几种解决方案:

1.把server response MIME改成 text/htmlargs.event.response。这种方法在处理json 的时候有效,但是可能不是一种好方法。

2.去掉multipart/form-data但是上传文件的时候没用。

3.用json的$.post 方法替代ajaxSubmit

在我的页面中是用的get方法去请求导出接口,改成post之后,问题解决。

 

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权