1

I wonder if my problem is my ajax call is to http, not https. Must I call with https or can I call with http?

I am compiling with PhoneGap cloud cli-5.2.0 ( iOS 3.9.1 / Android 4.1.1 / Windows 3.8.1)

I compile my package, install it on my Android Samsung, it starts up, and my $.ajax errors

errorThrown:undefined textStatus:error data:{"readyState":4,"responseText":"","status":404,"statusText":"Not Found"}

Any suggestions/ideas?

I read the following: jQuery Mobile + Phonegap on Android - no Ajax but its two years old and relates to an older version of phonegap.

My code requires no special magic - I do include phonegap.js but I do not use gps, camera, contacts etc etc

Using the code below, I do get my "deviceready" and "document ready" displayed. When I click on my login button (id='demologin') the function DemoLogin() is executed.

function onDeviceReady() {
    $("#demologin").on("click", DemoLogin );

    $("#demologin").after("<h3>deviceready</h3>");
    return true;
}

    $(document).ready(
    function()
    {
        document.addEventListener("deviceready", onDeviceReady, false);
        $("#demologin").after("<h3>document ready</h3>");
    });

If I were to guess, the ajax "404" leads me to believe its calling a URL that does not exist hence why I wonder if Android expects me to call https instead of http. The problem I have with this is the code works on iOS so I would have thought PhoneGap magic would lead me to believe if it runs on one, it would run on the other.

All help appreciated!

Community
  • 1
  • 1

2 Answers2

0

I also use ajax on phonegap app and it work good. You can make call to http. I think the url you called does not exist or there may be connection problems like when data is switched off.

Ahmadbaba46
  • 221
  • 2
  • 7
  • I know the URL is valid because 1) The app works fine on iOS, just not on Android 2) The URL is written in a variable, I display the variable on the screen (part of my debugging efforts) when $.ajax complete section is executed. –  Sep 15 '15 at 11:41
0

This is a old question but, possibly the solution will help someone who is googling it.

Add this code to your config.xml file:

<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />

because new release of Cordova need whitelist plugin.

Om Bissa
  • 63
  • 6