Ok I am using the Ext.data.ScriptTagProxy to pull json data from a remote server (which I happen to manage) and am receiving this error: Uncaught SyntaxError: Unexpected token :
I am querying a database with the following PHP page and encoding the results in 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 "}";
?>
And here is the code I am using to make the Cross domain call using 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
});
Anybody s开发者_开发百科ee anything unusual which would case the syntax error? Thanks in advance for your help!
For a start, I am having a hard time validating your json. Currently its wrapped in (parenthesis) rather than {brackets}
([{"id":"3","ingredients2":"4 oz. (1\/2 cup orange juice)","ingredients3"
...
,"ingredients":"6 oz. skim milk","website":null}]);
and not sure that javascript is too helpful, firebug for example would like to see "application/json" != "application/javascript" for laying out data. this doesnt impact parsing/linting though.
精彩评论