2014-02-07 98 views
0

嗨,我是新來的Sencha,我嘗試設置json請求數據到文件集。但它不起作用。請幫助我,我找不到錯誤。JSONP請求不能正常工作

這是我的JSON請求數據:

{"response":{"electric_current":103.7506250769956,"electric_power":120.62350489414762}} 

這是代碼。

Ext.define('AIOS_vis.view.Main', { 

    extend: 'Ext.tab.Panel', 
    xtype: 'main', 
    requires: [ 
     'Ext.TitleBar' 
    ], 

    config: { 
     listeners: { 
      activate: function() { 

       alert('gr'); 
       Ext.data.JsonP.request({ 
        url: 'http://localhost:8080/mock/GetCtPwer.php', 
        method: 'POST' 
        callbackkey: 'callback', 
        params: { 
         tap_id: 1 
        }, 

        scope: this,  /// fix handler scope 

        callback: function (response, value, request) { 
         var wattComponent = Ext.getCmp('watt'); 
         wattComponent.setValue(value.response.electric_power); 

         var ampereComponent = Ext.getCmp('ampere'); 
         ampereComponent.setValue(value.response.electric_current); 

        }, 

        failure: function (response, request) { 
         Ext.Msg.alert(response); 
        } 
       }); 

      } 
     }, 

     tabBarPosition: 'bottom', 

     items: [ 
      { 
       title: 'Home', 
       iconCls: 'home', 
       styleHtmlContent: true, 
       scrollable: true, 

       items: [ 
       { 
        docked: 'top', 
        xtype: 'titlebar', 
        title: 'Visual', 
       }, 
       { 
       xtype: 'fieldset', 
       instructions: 'Last Update: 2014/02/06:12:45:23', 
       items: [ 
       { 
        xtype: 'button', 
        text : 'current', 
        height: '40px', 
       }, 
       { 
        xtype: 'textfield', 
        id: 'watt', 
        label: 'Wattage (W):', 
        text: '1890.9W' 
       }, { 
        xtype: 'textfield', 
        id: 'ampere', 
        label: 'Amperage (A):', 
        text: '18.91A' 
       }] 
      }, 
       { 
        xtype :'titlebar', 
        style: 'background:#484848', 
        title : 'power</br>123.4Wh', 
        height: '100px' 
       } 
      ]} 

     ] 
    }, 
}); 

回答

0

你的web服務網址更改爲(例如)http://yoururl.com:8080/mock/GetCtPwer.php?jsonp=parseResponse ,並確保您的webserice的迴應是:

parseResponse({ 「迴應」:{ 「electric_current」:103.7506250769956, 「electric_power」:120.62350489414762 }})

你可以改變「parseResponse」爲任何你想要的。

+0

這不是工作.... :( –