![](/img/trans.png)
[英]Chrome Error - Resource interpreted as Script but transferred with MIME type text/plain
[英]Chrome Extension error when returning json: Resource interpreted as Script but transferred with MIME type text/json
我正在制作一个使用http://loopj.com/jquery-tokeninput/添加标记的Chrome扩展程序。
$(function() {
$("#token").tokenInput("http://localhost/token/search", {
preventDuplicates: true,
});
});
在我的php代码中,我返回了一个json编码的数组(并且通过应用程序本身使用了相同的函数并且正在工作):
echo json_encode($token_array);
exit;
但是,结果未正确返回,Chrome在控制台中报告以下错误:
资源被解释为脚本,但以MIME类型text / html传输
当我单击链接的源时,它似乎已正确格式化:
[
{
"id": "5",
"name": "token1"
},
{
"id": "3",
"name": "token2"
},
{
"id": "4",
"name": "token3"
}
]
我需要在我的php代码中设置标头吗? 我试过了:
header('Content-type: text/json');
这将导致以下错误:
资源被解释为脚本,但以MIME类型text / json传输:
当我尝试
header('Content-type: application/json');
它似乎没有发出请求。 我究竟做错了什么?
应为text/javascript
内容类型:
header('content-type:text/javascript');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.