1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    1
    Vote Rating
    0
    Craysis is on a distinguished road

      0  

    Default Unanswered: load json datas from proxy

    Unanswered: load json datas from proxy


    Hi all !
    I must loading datas from a WebService in Json format like that :

    Code:
    [
        {
            "CodeMission": "FOVA",
            "Dessertes": [],
            "HeureProbable": "19/09/2012 10:38",
            "HeureTheorique": "19/09/2012 10:38",
            "Numero": "127034",
            "Quai": null,
            "Retard": "00:00",
            "Sens": "P",
            "Voie": "2",
            "VoiePrecedente": null
        },
        {
            "CodeMission": "VOPA",
            "Dessertes": [
                {
                    "CodeTR3A": "BFX",
                    "Nom": "Le Bras de Fer"
                },
                {
                    "CodeTR3A": "EVC",
                    "Nom": "Evry Courcouronnes"
                }
            ],
            "HeureProbable": "19/09/2012 10:47",
            "HeureTheorique": "19/09/2012 10:47",
            "Numero": "126620",
            "Quai": null,
            "Retard": "00:00",
            "Sens": "P",
            "Voie": "A",
            "VoiePrecedente": null
        }
    ]
    So i have my 2 models :

    Code:
                    Ext.define('ChoixTrain', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeMission','HeureProbable','HeureTheorique','Numero','Quai','Retard','Sens','Voie','VoiePrecedente'],
                            hasMany: {model: 'Desserte', name: 'Dessertes'},
                            proxy: {
                                type: 'jsonp',
                                autoLoad:true,
                                url: 'https://plop.com/Trainservice.svc/GetListTrainsAtGare/COE',
                                method: 'POST',
                                params: {
                                    username: 'plop',
                                    password: 'plop'
                                },
                                headers: {
                                    'Accept': 'application/javascript'
                                },
                                reader: {
                                    type: 'json',
                                    model: 'ChoixTrain'
                                }
                            }
                        }
                    });
                    
                    Ext.define('Desserte', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeTR3A','Nom'],
                             belongsTo: 'ChoixTrain'
    
                        }
                    });


    and 1 store to load and retreive my datas :

    Code:
                    Ext.define('Desserte', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeTR3A','Nom'],
                             belongsTo: 'ChoixTrain'
    
                        }
                    });
                    
                    var trains = Ext.create('Ext.data.Store', {
                        model: 'ChoixTrain'
                    });
                    
                    trains.load({
                        callback: function() {
                            //the user that was loaded
                            var premierTrain = trains.first();
    
                            console.log("Premier Train : " + premierTrain)
                        }
                    });
    with the debuger I see my json string added as a script, so the webservice response is OK, but my "firstTrain" is undefined, and "trains" datas is empty !

    what the problem in my code ?

    Edit : I think the problem comes from my callbackKey, i have a script like "https://plop.com/..../...?callback=Ext.data.JsonP.callback1, but how can i acces to my data list now ?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,641
    Vote Rating
    434
    Answers
    3107
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Is the JSON that is returned in JSONP format?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread