Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
Sencha 2.0 and Codeigniter RESTful API generates Uncaught SyntaxError: Unexpected token :
我正在尝试将 sencha 提供从 codeiniter restful API 生成的 (JSON) 数据。我做了基于Net.tuts CI API教程的RESTful API
我收到错误未捕获语法错误:意外令牌:这是我的煎茶代码和CI代码
CI 代码
function user_get()
{
if(!$this->get('id'))
{
$this->response(NULL, 400);
}
$user = $this->user_model->get( $this->get('id') );
if($user)
{
$this->response($user, 200); // 200 being the HTTP response code
}
else
{
$this->response(NULL, 404);
}
}
生成的 JSON
{
name: "ALEX JOHN",
country: "USA",
city: "NY"
}
煎茶代码
Ext.application({
name: 'Sencha',
launch: function() {
Ext.create('Ext.DataView', {
fullscreen: true,
store: {
autoLoad: true,
fields: ['name', 'country','city'],
proxy: {
type: 'jsonp',
url: 'http://localhost/rest_api/index.php/users/user/id/2',
callbackKey: 'callback',
callback: function(result) {
console.log(result) ;
},
reader: {
type: 'json'
}
}
},
itemConfig: {
tpl: '<p>{city}</p>'
}
});
}
});
我不知道这个地区是从哪里来的。它来自我的 JSON 数据格式吗?煎茶是如何消费的?好心有人帮忙。谢谢
如果您要请求 JSONP,则需要将返回的 JSON 包装在回调中。 在控制器中,尝试将有效响应替换为:
//Is the GET field callback set? If so, wrap the user object in it
if (isset($_GET['callback'])){
$user=$_GET['callback'].'('.json_encode($user).')';
//And manually create the response
header("Status: 200 OK"."'r'n");
header("Date: ".gmdate(DATE_RFC822)."'r'n");
header("Content-Type: application/javascript charset=UTF-8'r'n");
header("Content-Length: " . strval(strlen($user))."'r'n");
echo $user;
} else //Use thhe API to gnerate the response as normal
$this->response($user, 200);
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- Javascript未捕获语法错误意外的标识符错误
- 为什么忽略了eval()代码中的语法错误
- 难以访问的JS环境中的语法错误
- 未捕获的语法错误:意外的标记{
- "未捕获的语法错误:意外的标记}"
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- $(input[]).仅在firefox中出现每个抛出语法错误
- 为什么浏览器没有为语法错误抛出异常
- 错误:语法错误,无法识别的表达式:不支持的伪:无效/RectJS/Unit Testing
- 未捕获的语法错误:意外的令牌,
- jQuery.getJSON失败,语法错误
- "未捕获的语法错误:意外的标记"角度JS
- 参数列表Three.js之后的未捕获语法错误:缺少)
- 循环的Javascript冻结浏览器,没有语法错误
- 为什么匿名函数本身就是javascript中的语法错误
- 这怎么不是语法错误?这毫无意义!(javascript)
- 语法错误:缺少:在属性 ID 之后
- 未捕获错误:语法错误,无法识别的表达式:input[@type=submit]