2011-06-03 83 views
0

好的我正在使用Ext.data.ScriptTagProxy從遠程服務器(我碰巧管理)中提取json數據並收到此錯誤:未捕獲的SyntaxError:意外的令牌:使用Ext.data.ScriptTagProxy發生意外的令牌語法錯誤

我查詢用下面的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 "}"; 
?> 

這裏是我使用使用煎茶,使跨域調用的代碼:

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

首先,我很難validating你的json。目前其包裹在(括號),而不是{括號}

([{"id":"3","ingredients2":"4 oz. (1\/2 cup orange juice)","ingredients3" 
... 
,"ingredients":"6 oz. skim milk","website":null}]); 

,並不能肯定JavaScript是太大的幫助,螢火蟲例如希望看到「應用/ JSON」!=「應用程序/ JavaScript的」爲佈局數據。這並不影響解析/ linting。