返回json时Chrome浏览器扩展错误:资源解释为脚本,但使用MIME类型text / json传输 [英] Chrome Extension error when returning json: Resource interpreted as Script but transferred with MIME type text/json
问题描述
我制作一个Chrome扩展程序,使用 http://loopj.com/jquery-tokeninput/添加标记。
$(function(){
$(#token)。tokenInput( http:// localhost / token / search,{
preventDuplicates:true,
});
});
在我的php代码中,我返回一个json编码数组(并且通过应用程序使用相同的函数本身和工作):
echo json_encode($ token_array);
出口;
然而,结果并未正确返回,并且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');
它似乎没有提出请求。我做错了什么?
类型: header('content-type:text / javascript');
I am making a chrome extension that uses http://loopj.com/jquery-tokeninput/ to add tokens.
$(function() {
$("#token").tokenInput("http://localhost/token/search", {
preventDuplicates: true,
});
});
In my php code I am returning a json encoded array (and the same function is used via the app itself and is working):
echo json_encode($token_array);
exit;
However the results are not being returned correctly and chrome reports the following error in the console:
Resource interpreted as Script but transferred with MIME type text/html
When I click the link the the source, it appears to be formatted correctly:
[
{
"id": "5",
"name": "token1"
},
{
"id": "3",
"name": "token2"
},
{
"id": "4",
"name": "token3"
}
]
Do I need to set headers in my php code? I tried:
header('Content-type: text/json');
which creates the following error:
Resource interpreted as Script but transferred with MIME type text/json:
and when I try
header('Content-type: application/json');
It doesn't seem to make the request. What am I doing wrong?
Should be text/javascript
content type:
header('content-type:text/javascript');
这篇关于返回json时Chrome浏览器扩展错误:资源解释为脚本,但使用MIME类型text / json传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!