【问题标题】:JsonP scriptTag extjs4.1 issueJsonP scriptTag extjs4.1 问题
【发布时间】:2012-08-14 20:32:18
【问题描述】:

我收到以下服务器响应:

回调({ “数据”: [ { "id": "13_gnomodotiseis", “id1”:13, "title": "5/2009 ΓΝΜΔΕΙΣΑΠ 2009", "text": "5/2009 ΓΝΜΔΕΙΣΑΠ", “模型”:“gnomodotiseis”, "body": "σίλει...", “类型”:“文本”, “历史”:“旧”, “网址”:“”, "search_tag": "Γνωμοδοτήσεις", “新元素”:“真” } ], “数据集”: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'
        }
    } 

});

我在萤火虫中看到的网址:

http://localhost:8090/openbd/ktimatologio-final/resources/cfScripts/nea_stoixeia/GetNews.cfc?&_dc=1345305032559&method=jsonP&page=1&start=0&limit=25&group=[{"property"%3A"search_tag"% 2C"direction"%3A"ASC"}]&sort=[{"property"%3A"search_tag"%2C"direction"%3A"ASC"}]&callback=Ext.data.JsonP.callback2

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

我的问题是:

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

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

我真的需要这方面的帮助。

提前谢谢你,

汤姆

希腊

【问题讨论】:

    标签: cross-domain jsonp extjs4.1


    【解决方案1】:

    您在响应中使用了错误的函数名称。如果你查看请求url,你可以看到它是在你的响应需要调用的函数名中发送的,你需要在响应数据中使用它:&callback=Ext.data.JsonP.callback2,所以响应应该调用函数 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。

    【讨论】:

    • 非常非常感谢!我还没有想到我必须将“Ext.data.JsonP.callback2”放到服务器的请求中。我是多么愚蠢!再次感谢您!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2021-05-09
    • 2011-10-14
    • 2013-04-29
    • 2013-04-25
    • 1970-01-01
    • 2013-08-23
    相关资源
    最近更新 更多