您的位置:首页 > 移动开发

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

2016-11-15 16:22 513 查看
今天发布一个项目的时候,遇到了一个奇怪的问题,一个后台管理系统的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/html
args.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/html
args.event.response
。这种方法在处理json
的时候有效,但是可能不是一种好方法。

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

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

在我的页面中是用的get方法去请求导出接口,改成post之后,问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  调试
相关文章推荐