Hybrid View
-
14 Nov 2012 8:03 AM #1
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):
You can see that i'm using only a minimal URL, this is working on web server.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(); } } });
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
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)).Code:"url": "http://myServerAlias:8080/myApp/",
Thank for reading !
-
15 Nov 2012 12:33 AM #2
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) :
But this is not clean i'm looking for a better solution !Code:Ext.Ajax.setMethod("POST"); Ext.Ajax.on({ beforerequest: function(dataconn, options, eOpts) { options.url = "http://myServerAlias:8080/myApp/" + options.url; } });
-
15 Nov 2012 12:59 AM #3Sencha Premium Member
- Join Date
- Feb 2012
- Location
- Berne, Switzerland
- Posts
- 581
- Vote Rating
- 32
- Answers
- 34
-
15 Nov 2012 1:43 AM #4
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, } });


Reply With Quote