JsonP scriptTag extjs4.1问题

时间:2012-08-18 20:18:34

标签: cross-domain jsonp extjs4.1

我收到了以下服务器响应:

  

回调({       “数据”:[           {               “id”:“13_gnomodotiseis”,               “id1”:13,               “title”:“2009年5月ΓΝΜΔΕΙΣΑΠ2009”,               “text”:“2009年5月ΓΝΜΔΕΙΣΑΠ”,               “模特”:“gnomodotiseis”,               “身体”:“σίλει......”,               “type”:“text”,               “历史”:“老”,               “url”:“”,               “search_tag”:“Γνωμοδοτήσεις”,               “new_element”:“true”           }       ]       “dataset”:1})

我有这样的商店定义:

var baseUrl = 'http://localhost:8090/'; 

Ext.define('Ktimatologio.store.NewSingleBlockStore', {
    extend: 'Ext.data.Store',
    alias: 'widget.newsingleblockstore',

    requires: ['Ktimatologio.model.NewSingleBlockModel'],

    model: 'Ktimatologio.model.NewSingleBlockModel',

    groupField: 'search_tag',

    fields: [    
        {name:'id', mapping:'id'},
        {name:'id1', mapping:'id1'},
        {name: 'text', mapping: 'text'},
        {name: 'title', mapping: 'title'},
        {name: 'fek', mapping: 'fek'},
        {name: 'date', mapping: 'date'},
        {name: 'descr', mapping: 'description'},
        {name: 'model', mapping: 'model'},
        {name: 'body', mapping: 'body'},
        {name: 'type', mapping: 'type'},
        {name: 'history', mapping: 'history'},
        {name: 'src', mapping: 'url'},
        {name: 'search_tag', mapping: 'search_tag'},
        {name: 'new_element', mapping: 'new_element'},
        {name: 'new_table', mapping: 'new_table'}
        ],

    autoLoad: true,    

    proxy: {
        //type:'ajax',
        type:'jsonp',
        url: baseUrl + 'openbd/ktimatologio-final/resources/cfScripts/nea_stoixeia/GetNews.cfc?',
        callbackKey: 'callback',
        extraParams: {
            method: 'jsonP'
            },
        reader:{
            type: 'json',
            root: 'data'
        }
    } 

});

我在firebug中看到的网址:

  

的http://本地主机:8090 / openbd / ktimatologio决赛/资源/ cfScripts / nea_stoixeia / GetNews.cfc&安培; _dc = 1345305032559&安培;方法= JSONP&安培;页= 1&安培;开始= 0&安培;限制= 25安培;组= [{ “属性” %3A “SEARCH_TAG” %2C “方向” %3A “ASC”}]&安培;排序= [{ “属性” %3A “SEARCH_TAG” %2C “方向” %3A “ASC”}]&安培;回调= Ext.data.JsonP.callback2

Firebug给我错误:“ReferenceError:未定义回调”

我的问题是:

Ext.data.JsonP.callback2从哪里弹出url?

我在这里缺少什么? Extjs4.1中的jsonP如何工作?

我真的需要帮助。

提前谢谢你,

汤姆

希腊

1 个答案:

答案 0 :(得分:1)

您在响应中使用了错误的函数名称。如果您查看请求网址,您可以看到它正在发送您的响应需要调用的函数名称,并且您需要在响应数据中使用它:& callback = Ext.data.JsonP.callback2,so响应应该调用函数Ext.data.JsonP.callback2而不是简单的回调。因此,对于您的示例,服务器应该将其作为响应返回:

Ext.data.JsonP.callback2({ "data": [ { "id": "13_gnomodotiseis", "id1": 13, "title": "5/2009 ΓΝΜΔ ΕΙΣΑΠ 2009", "text": "5/2009 ΓΝΜΔ ΕΙΣΑΠ ", "model": "gnomodotiseis", "body": "σίλει...", "type": "text", "history": "old", "url": "", "search_tag": "Γνωμοδοτήσεις", "new_element": "true" } ], "dataset": 1 })

这是因为在请求中发送了callback = Ext.data.JsonP.callback2。