2013-08-01 135 views
0

Sencha新手,我使用以下代碼嘗試獲取JSON數據。出於某種原因,它返回null,但我知道URL正在返回值,因爲我在另一個項目中使用它。如何使用Sencha獲取JSON數據

// Make the JsonP request 
     Ext.data.JsonP.request({ 
      url: 'http://xxx.azurewebsites.net/login', 
      crossDomain: true, 
      type: "GET", 
      dataType: "json", 
      callbackKey: 'jsoncallback', 
      callback: function(successful, data) { 
       alert(JSON.stringify(data)); 
      } 
     }); 

有人可以指出我缺少的東西。

+0

什麼是您的網址返回?請記住,JSON-P需要使用'callbackKey'作爲函數名稱在函數內返回數據。 – kevhender

回答

1

你需要添加範圍:這個屬性來調用回調函數,試試像這樣。

Ext.data.JsonP.request({ 
    url: 'http://xxx.azurewebsites.net/login', 
    crossDomain: true, 
    type: "GET", 
    dataType: "json", 
    callbackKey: 'callback', 
    scope: this, 
    callback: function (response, value, request) { 
     var result = Ext.decode(response.responseText); 
     alert(result.propertyName); 
    } 
});