2013-08-01 88 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); 
    } 
});