好的我正在使用Ext.data.ScriptTagProxy从远程服务器(我碰巧管理)中提取json数据并收到此错误:未捕获的SyntaxError:意外的令牌:
我使用以下PHP页面查询数据库并将结果编码为json:
<?php
header('Content-Type: text/javascript');
$db_name = "foo"; // The name of the database being used.
$db = mysql_connect("localhost", "foo user", "foo pass") or die ("Unable to connect to database.");
mysql_select_db("$db_name", $db);
echo '{"recipes": ';
$query = "SELECT * FROM wp_recipes";
$result=mysql_query($query);
$_ResultSet = array();
while ($row = mysql_fetch_assoc($result)) {
$_ResultSet[] = $row;
}
echo json_encode($_ResultSet);
echo "}";
?>
以下是我用来使用Sencha进行跨域调用的代码:
var store = new Ext.data.Store({
model : 'Recipes',
sorters: [
{property: 'recipeName', direction: 'ASC'}
],
getGroupString : function(record) {
return record.get('recipeName')[0];
},
proxy: new Ext.data.ScriptTagProxy({
url: 'http://myvisalusdiet.com/app/json_output2.php'
}),
reader: new Ext.data.JsonReader({
root: 'recipes',
idProperty : 'recipeName',
id: 'id'
}),
autoLoad : true
});
任何人都会看到任何不寻常的语法错误?在此先感谢您的帮助!
答案 0 :(得分:0)
首先,我的json很难validating。目前它包裹在(括号)而不是{括号}
([{"id":"3","ingredients2":"4 oz. (1\/2 cup orange juice)","ingredients3"
...
,"ingredients":"6 oz. skim milk","website":null}]);
并且不确定javascript是否太有用,例如firebug希望看到“application / json”!=“application / javascript”来布局数据。这不会影响解析/ linting。