Results 1 to 7 of 7

Thread: Cannot load stores using jsonp extjs4.1

  1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    107
    Vote Rating
    1
      0  

    Default Cannot load stores using jsonp extjs4.1

    I am trying to load ext data stores using jsonp. The below code is working fine when i am using ajax and making requests on the same domain.

    Code:
    var baseUrl = 'http://localhost:8090/'; 
    
    Ext.define('Ktimatologio.store.NewWholeBlockStore', {
        extend: 'Ext.data.Store',
        alias: 'widget.newsingleblockstore',
    
        requires: ['Ktimatologio.model.NewWholeBlockModel'],
    
        model: 'Ktimatologio.model.NewWholeBlockModel',
    
        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/GetNewTables.cfc?',
            extraParams: {
                method: 'getNewTables'
                },
            reader:{
                type: 'json',
                root: 'data'
            }
        }
    When i run the code i see an error on firebug:

    Code:
    SyntaxError: invalid label
    {"data":[{"id":"1_n_2308_1995","id1":1,"title":"????? 1&nbsp??? ?? 114&nbsp15.6....
    
    GetNew...llback2 (line 1, column 1)
    I am stuck!
    Any help is much appreciated!
    Tom
    Greece

  2. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,015
    Vote Rating
    182
      0  

    Default

    Is the server responding correctly? Did you verify the response?

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    107
    Vote Rating
    1
      0  

    Default

    Thank you for your reply,
    Te response is 100% pure JSON. Still not get it. I am wresting with this a week now!

    The response:

    Code:
    {"data":[{"id":"13_gnomodotiseis","id1":13,"title":"5/2009 ????  ?????<br/>&nbsp2009","text":"5/2009 ????  ?????<br/>","model":"gnomodotiseis","body":"(?/??  2009/302)<br/>\t????????????.<br/>\t? ???????? ????????  ??? ????? ??? ??????????????? ??? ????????????? ????? ??? ????????  ???????, ?? ????? ???? ??? ???? ??? ????????? ??? ??? ????????????? ??  ?????? ??????????? ??? ??? ???????????? ???? ???????? ???????????? ???  ?????????????, ???????? ???????? ??? ???????????? ??? ??????????????  ???????????? ??? ??? ??????????????? ???????????? ???  ????????.<br/>\t?????????? ???????? ???????? ??? ?.?. ???  ????.<br/>\t???? ?? ??????? ??????????????? ?????????? ???????  ????????, ??????? ????????? ??? ????????? ??? ????????? ???????????  ????????? ?? ????????? ?? ??????????? ???? ??? ???????????? ???  ?????????????? ????????? ??? ????????.<br/>\t????????? ?? ???????  ??? ?????????? ????? ??? ?? ???????? ??? ??  ??????????????.<br/>??????????????:  ???????...","type":"text","history":"old","url":"","search_tag":"?????????????","new_element":"true"}],"dataset":1}
    Any help is much appreciated!

  4. #4
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,015
    Vote Rating
    182
      0  

    Default

    It should not be json, it should be javascript - a function. Details here

    http://remysharp.com/2007/10/08/what-is-jsonp/

  5. #5
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    107
    Vote Rating
    1
      0  

    Default

    Thank you again

  6. #6
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    107
    Vote Rating
    1
      0  

    Default

    Still having problem,

    The response:

    Code:
    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
    })
    The url:

    Code:
    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
    The store:

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

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

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,377
    Vote Rating
    858
      0  

    Default

    Because that's the function it's expecting to call. It's covered in the docs: http://docs.sencha.com/ext-js/4-0/#!...ta.proxy.JsonP
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •