Hybrid View

  1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    10
    Vote Rating
    0
    moisan.j is on a distinguished road

      0  

    Default Unanswered: How can i indicate to native app the distant server URL for ajax call

    Unanswered: How can i indicate to native app the distant server URL for ajax call


    Hi there !

    I'm training at sencha touch frame work, i've build a small application with ajax call.

    I've use Sencha CMD to build native app over Android (sencha app build native), that's working nice except ajax call url is not found !

    In my App, i use Ajax like this (ajax just send true or false):
    Code:
            Ext.Ajax.request({
                url: "services/user/online",
                success: function(response){
                    Ext.fly("canvasloader-container").destroy();
    
    
                    if(eval(response.responseText)) {
                        Ext.Viewport.removeAll(true, true);
                        Ext.Viewport.add(Ext.create("App.view.Main")).show();
                    } else {
                        Ext.Viewport.removeAll(true, true);
                        Ext.Viewport.add(Ext.create("App.view.Login")).show();
                    }
                }
            });
    You can see that i'm using only a minimal URL, this is working on web server.

    But when i use my app in Android native App that's fail !

    I've write in my app.json file the following parameters, but it's seems sencha cmd do not care of it

    Code:
    "url": "http://myServerAlias:8080/myApp/",
    I've miss something ? Is my parameter good ? If i call the url in navigator of the android terminal that's working (so no DNS trouble)).

    Thank for reading !

  2. #2
    Sencha User
    Join Date
    Oct 2010
    Posts
    10
    Vote Rating
    0
    moisan.j is on a distinguished road

      0  

    Default


    I've write in the launch function of the app for native App (i remove it for web App else we have cross domain error) :

    Code:
            Ext.Ajax.setMethod("POST");
    
    
            Ext.Ajax.on({
                beforerequest: function(dataconn, options, eOpts) {
                    options.url = "http://myServerAlias:8080/myApp/" + options.url;
                }
            });
    But this is not clean i'm looking for a better solution !

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Berne, Switzerland
    Posts
    714
    Answers
    41
    Vote Rating
    42
    ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about

      0  

    Default


    I use something like this one here: http://mitchellsimoens.com/2012/06/s...encha-command/

  4. #4
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Antibes
    Posts
    66
    Answers
    4
    Vote Rating
    0
    Gaspard22 is on a distinguished road

      0  

    Default


    you should'nt use an Ajax Call but a JSONP call to avoid the cross-domain pb.

    Code:
    Ext.data.JsonP.request({
                                    url: 'http://myServerAlias:8080/myApp/example.php',
                                        //callbackKey: 'callback',
                                        params: {
                                            Param1:value1,
                                           Param2:value2,
                                        }
                                    });

Thread Participants: 2