JSONP请求不起作用



嗨,我是Sencha的新手,我尝试将JSON请求数据设置为FiledSet。但是它行不通。请帮助我我找不到错误。

这是我的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'
                }
            ]}
        ]
    },
});

将您的Web服务URL更改为(例如)http://yoururl.com:8080/mock/getctpwer.php?jsonp=parseresponse并确保您的WebSerice对此做出回应:

parseresponse({"响应":{" electric_current":103.7506250769956," electric_power":120.62350489414762}}}

您可以将" parseresponse"更改为您想要的任何东西。

最新更新