Error in App and gets force close - android

In my android phonegap app,sometimes i get the application error as
Note when moving from one page to another page am getting this error
**"A network error occurred.(file:///android_asset/www/home/home.html?userid=91)"**
and app gets force closed .Please guide me to solve this problem.I am also attaching the screenshot.Its cuming in android 4.x versions
update
$.ajax({
cache: false,
async: true,
type: "POST",
dataType: "json",
url:url +"Status",
data: '{"NO" : "' + no}',
contentType: "application/json;charset=utf-8",
success: function (r)
{
window.open("../index/index.html?id="+id);
},
error: function (e)
{
alert("No Network");
}
});

There is a bug in the Android 4.x OS when passing parameters along the URL:
https://code.google.com/p/android/issues/detail?id=17535
https://code.google.com/p/android/issues/detail?id=17327

Related

ajax call fail in Cordova app on real device but works fine in the emulator

I've developed a mobile app using cordova platform ,it just work fine in ripple simulator but if i try to on real device(android) using USB cable then it throw error on ajax call ?it seems repeated question but i've tried all the sugestion found on googling which don't work for me.
//my ajax call code
$("#loginButton").off().click(function (e) {
e.preventDefault();
var data = JSON.stringify({
PortalID: 1,
UserName: $('#txtuserName').val(),
Password: $('#txtpassword').val(),
});
$.ajax({
contentType: "application/json; charset=utf-8",
type: 'POST',
url:'http://192.168.01.10:8043/BackEndWebService/LoginWebService.asmx/LoginUser',
dataType: 'json',
data:data,
success: function(result){
alert (result)
},
error: function(error){
alert("error");
}
});

How to make ajax-like call in Android

I am working on Android application that will make consistent api calls to a server and parse JSON from the server. ( Actually this application is an web game.) Now we have an web version written with jQuery in which $.ajax() calls are used:
$.ajax({
url: "https://www.example.com/api/base_info/",
type: "POST",
dataType: "json",
crossDomain: true,
data: {
"client_type": "web",
"id": userID,
"access_key": accessToken
},
success: function (data) {
username = data.name;
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
}
});
So how can I duplicate this in Android? I have searched on the internet and I see many different approaches. I am not sure which is best for Android platform? Would you please give some suggestions? Please use the code above as an example if possible. Thanks in advance!

On android Cordova 2.1 app, ajax request always being interrupted and returns HTML-page with offer to update Browser (Dolphin HD)

I have a really weird behaviour on android app (Cordova 2.1).
I simple use code like that:
$.ajax({
type: "GET",
url: this.serverUrl,
data:data,
dataType: "json",
timeout: 3000, // in milliseconds
success: function(data) {
//never gets here...
},
error: function(request, status, err) {
//always gets here
console.log(request.responseText);
}
});
request.responseText always contains html-page with this content: http://dimalezhnev.ru/assets/tmp/html.txt (I placed the output in this file).
I draw a picture in my mind that browser while doing ajax request drop it and returns response with that html - forces user to update the browser in agressive style.
How to prevent it? I just can't imagine why is this happening now.

Can't access php file from other domain

I written a android mobile application in JQuery Mobile and PhoneGap in Eclipse. In the application I am calling a jquery ajax to load list of data from other domain.
My jquery ajax call code is:
$.ajax({
type: "POST",
url: WEBSERVICE_URL,
async: false,
data: dataString,
dataType: 'json',
crossDomain: true,
success: function(data) {
loginData = new Object(data);
hideActivityIndigator();
if(loginData.success == "true"){
$.mobile.changePage("#selectionScreen", "slide", false, true);
} else {
$("#message_ajax").html("Invalid UserName/Password.");
}
},
error: function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
hideActivityIndigator();
}
});
The variable "WEBSERVICE_URL" has a other domain php service url.
On executing above code on "pageview" event I am getting following error
Error: NETWORK_ERR: XMLHttpRequest Exception 101
Any solution is there to access service from other domain in JQuery Mobile + PhoneGap...?
I think this might solve your problem.
If you are using Phonegap/Cordova you should be able to call cross-domain web-services.. are you using an emulator or a phone?
As for emulator I would recommend Ripple, you can add it as a Chrome extension or Download the standalone version

AJAX to Sharepoint Server with Phonegap and JQuery Mobile not working

I have the following Problem. In the Phonegap App(for Android) I want to make an AJAX-Call to connect with a Sharepoint Server, with the following Code:
$.ajax({
url:"https://xxx/_vti_bin/lists.asmx",
beforeSend: function( xhr ){
xhr.setRequestHeader(
"SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/GetListCollection"
);
xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");
},
dataType:"xml",
contentType: "application/xml; charset=utf-8",
timeout:10000,
type:'POST',
cache: false,
username: "username",
password: "password",
data: soapEnv,
success:function(data) {
// alert data
var serializer = new XMLSerializer();
serialized = serializer.serializeToString(data);
alert(serialized);
},
error:function(XMLHttpRequest,textStatus, errorThrown) {
// alert errors
alert("Error status :"+textStatus);
alert("Error type :"+errorThrown);
alert("Error message :"+XMLHttpRequest.responseXML);
alert("Error statustext :"+XMLHttpRequest.statusText);
alert("Error request status :"+XMLHttpRequest.status);
},
complete: function(jqXHR, textStatus){
alert(textStatus);
}
});
When I try to run it on the Android Emulator the error messages are:
Error status: error
Error type:
Error message: undefined
Error statustext: error
Error request status: 0
However when I try to run it on my Browser (Chrome) with disabled websecurity (because of same origin policy) it works all fine. Phonegap normally shouldn't care about SOP because of the file:/// Protocol. I added the following to 'mobileinit':
$(document).bind("mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
But when I run the same Code in Chrome without websecurity disabled, I get exactly the same errors as in the Android Emulator.
I also tried an AJAX call to wikipedia (with html instead of xml, and GET instead of POST), and that worked without a problem.
Also I think the AJAX to Sharepoint doesn't even get fired (no traffic in Fiddler2, if I managed to configure it the right way)
So I am really stuck with this problem since 2 days now, if anyone knows how to make this ajax call work, it would made me so happy :-)
(soapEnv is the XML envelope, sent to the server)
Well I know that once upon a time jQuery had a bug where it treated a request status of 0 as an error. When running from the file protocol a status of 0 is the same this as a 200 (OK). You may need to update your version of jQuery.
Alternatively to test my theory just do a plain vanilla XHR request to your service to see if it works. Here is my stock example:
http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html

Categories

Resources