AL-Kateb
AL-Kateb

Reputation: 2962

Ext Js, Ext.Ajax.request not working on mobile device

I was trying to build an app with sencha touch 2, and phonegap, I'm using online phonegap build service, http://build.phonegap.com

I have a problem, the app is working perfectly fine on my computer, on all browsers, and it is also working fine on mobile phone when I open it from chrome browser, I also tried 'Phonegap App Desktop' which runs a server that transfers the app to your mobile device, the app works on the mobile there as well.

But not when I build the apk and install it on my mobile. Everything works except the Ajax request, here's a snippet for my ajax request.

Ext.Ajax.request({
    url: 'http://192.168.0.200/DVD/store.php',
    timeout:80000,
    callback: function(options, success, response) {
        var home = Ext.getCmp('home');
        home.setHtml(response.responseText);
    }
});

I was devastated cause' I could swear it worked before, so I created a new out of the box app and created a button, and added the above function to it, but that did not work.

What I'm doing is, building the app with sencha sencha app build android Then I zip the android dir content, upload it to phonegap build service, and I then install it on my phone, everything works except the ajax request.

I don't have android SDK on my computer so I have to use phonegap online build

What am I missing here?

Thanks

Upvotes: 0

Views: 777

Answers (1)

Simon Prickett
Simon Prickett

Reputation: 4148

If you are using Cordova 5.x you will want to check that your Content Security Policy is properly set in the head of your index.html. You will want a connect-src clause in there allowing connections to http://192.168.0.200

So, use something like the following:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://192.168.0.200">

This should allow Android devices to access your server assuming that the Android device is on a network where 192.168.0.200 resolves to your server.

Should you in future port your application to iOS, you will also need to configure Apple's App Transport Security to allow wildcard access to all non SSL servers, or configure an exception to allow iOS 9 devices to make http connections to 192.168.0.200. A blog post talking you through the process can be found here.

Upvotes: 1

Related Questions