javascript js 警告:资源被解释为脚本但使用 MIME 类型文本/纯文本传输
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7338983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
js warning: Resource interpreted as Script but transferred with MIME type text/plain
提问by tom81
i′m firing an ajax/jsonp request to my cloudant app:
我正在向我的 Cloudant 应用程序发出 ajax/jsonp 请求:
var obj = $.ajax({
url: "http://xyz",
dataType: 'jsonp',
success: function(data) {
//SOME CODE
},
error: function() {
//SOME CODE
}
});
the response is ok and i can read out my data. but I′m getting the following js warning:
响应正常,我可以读出我的数据。但我收到以下 js 警告:
Resource interpreted as Script but transferred with MIME type text/plain.
i need to make this request an jsonp request (cross domain policy), AFAIK jsonp returns as a script and gets executed by the browser. do i have to set a request header? I tried it with the 'accepts' and 'converters' options, but didn't make it work yet. (I′m using GoogleChrome, but also happens in Safari/FF)
我需要将此请求设为 jsonp 请求(跨域策略),AFAIK jsonp 作为脚本返回并由浏览器执行。我必须设置请求标头吗?我尝试了“接受”和“转换器”选项,但还没有让它工作。(我使用的是 GoogleChrome,但也发生在 Safari/FF)
cheers, tom
干杯,汤姆
PS: I want to get rid of the warning as this ajax request gets triggered every 2 seconds. So the console looks pretty bad...
PS:我想摆脱警告,因为此 ajax 请求每 2 秒触发一次。所以控制台看起来很糟糕......
回答by Jacob
The server should send a Content-Type
header set to text/javascript
when it sends the JSONP script.
服务器应该在发送 JSONP 脚本时发送一个Content-Type
设置为的标头text/javascript
。
回答by Robert Newson
CouchDB itself is sending the text/plain content-type. The only other type you can convince it to send is 'application/json' if you send 'Accept: application/json' as a header.
CouchDB 本身正在发送文本/纯内容类型。如果您将“接受:应用程序/json”作为标题发送,您可以说服它发送的唯一其他类型是“应用程序/json”。
It seems that CouchDB should send text/javascript if delivering a jsonp response, though. If you could file a ticket I'm sure it would get done.
不过,如果提供 jsonp 响应,CouchDB 似乎应该发送文本/javascript。如果你能提交一张票,我相信它会完成。
回答by Steve Benner
Are you sending any encoding information in the headers? I had a problem with CouchDB responses and discovered that adding charset=utf-8
to my Accept
or Content-Type
heading resulted in CouchDB returning the text/plain
content instead of the application/json
I was expecting. Perhaps you can solve this by altering your header if the case is similar enough.
您是否在标头中发送任何编码信息?我遇到了 CouchDB 响应的问题,发现添加charset=utf-8
到我的Accept
或Content-Type
标题会导致 CouchDB 返回text/plain
内容而不是application/json
我期望的内容。如果情况足够相似,也许您可以通过更改标题来解决此问题。
回答by genesis
Problem is on target server, because it's setting Content-Type: Text/plain
问题出在目标服务器上,因为它正在设置 Content-Type: Text/plain
You can't enforce it without access to target server. It should be Content-Type: text/javascript
您无法在无法访问目标服务器的情况下强制执行它。它应该是Content-Type: text/javascript