1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      0  

    Default Cannot load stores using jsonp extjs4.1

    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
    2,713
    Vote Rating
    104
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


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

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      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
    2,713
    Vote Rating
    104
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      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
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      0  

    Default


    Thank you again

  6. #6
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      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
    16,662
    Vote Rating
    584
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      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!

Thread Participants: 2

Tags for this Thread