JsonP scriptTag extjs4.1 issue

时光毁灭记忆、已成空白 提交于 2019-12-13 04:03:20

问题


i got the following server response:

callback({ "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 })

I have a store definition like this:

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'
        }
    } 

});

The url that i am seeing in firebug:

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 gives me error: "ReferenceError: callback is not defined"

My questions are:

From where does Ext.data.JsonP.callback2 pops up in the url?

What am i missing here? How jsonP in Extjs4.1 works?

I really need help on this one.

Thank you in advance,

Tom

Greece


回答1:


You are using the wrong function name in the response. If you look at the request url, you can see that it is sending in the function name that your response needs to call, and you need to use it in the response data: &callback=Ext.data.JsonP.callback2, so the response should call the function Ext.data.JsonP.callback2 instead of just plain callback. So in the case of your example, the server should be returning this instead as the response:

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 })

This is because callback=Ext.data.JsonP.callback2 was sent in the request.



来源:https://stackoverflow.com/questions/12021947/jsonp-scripttag-extjs4-1-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!