pdschuller
pdschuller

Reputation: 584

Android PhoneGap app made in Eclipse won't run jQuery ajax call

I have a barebones index.html, Anddroid Phonegap project in Eclipse that will not execute jQuery Mobile ajax calls. LogCat displays the following messages and the app crashes CordovaWebView: TIMEOUT ERROR! CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful.

Interesting facts: 1.) Eclipse installs and runs the app fine if I comment out the ajax call. 2.) I use the same ajax pattern in an .apk that I get by processing an html-css-javascript app through PhoneGap Build, and it works fine.

Details: In Eclipse Juno, I have an Android PhoneGap project (it uses the ADT and cordova-1.9.0.jar) with an index.html file which incorporates the following .js files in the following order:

<script type="text/javascript" src="Scripts/cordova-1.9.0.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.6.2.min.js"></script>
<script src="Scripts/temp.js" type="text/javascript"></script>

the temp.js file has this in it

$(document).ready(function(){
var theUrl = 'http://www.myDomain.biz/WebServices/gg.svc/';
console.log("theUrl + GetHelpFile = " + theUrl + "GetHelpFile");
$('div#divTarget').html("theUrl + GetHelpFile = " + theUrl + "GetHelpFile");

$.ajax({
type: "GET",
cache: false,
dataType: 'jsonp',
url: theUrl + "GetHelpFile",
contentType: "text/plain",
success: function (theJson) {
var help_file = $(theJson);
$('div#divHelpFile').html(help_file);
},
error: function ($theData) {
var tt = $theData;
alert(tt);
}
});
});

The project has

and all the <uses-permissions>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

the Run configuration I am using in Eclipse targets a 4.0 AVD and that all works fine. When I comment out the ajax call, Eclipse creates the .apk file, opens the AVD, installs the app, and it runs fine. Also, I made a website in IIS for the same index.html file, in the same directory, and the page loads in the browser and the ajax runs fine.

I increased the timeout period and that did not help

super.setIntegerProperty("loadUrlTimeoutValue", 60000);

What do you think I need to do to get the ajax call to execute in my Eclipse-Android-PhoneGap project?

Thanks

Upvotes: 0

Views: 2603

Answers (1)

gorgi93
gorgi93

Reputation: 2535

You should use different type of ajax call:

$.get('http://yourdomain.com/index.php', function (data) {
alert(data);
});

phonegap android ajax call doesnt work here is my solution.

Upvotes: 2

Related Questions