currently i using this code in phonegap application
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://192.168.1.19:8080/searchMobile?categoryRequest=true", true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function() {alert(xmlhttp.status);
if (xmlhttp.readyState == 4) {
var responseObject = eval("(" + xmlhttp.responseText + ")");
var results = responseObject.result;
if (results != null)
{
var resLength = results.length;
category.length = category.length + resLength;
for ( var i = 0; i < resLength; i++)
{
category.options[category.length - (resLength - i)].innerHTML = results[i].categoryName;
$(category).selectmenu("refresh");
}
}
}
this code is working in android but when i run this code on iphone it gives status 0 means doesn’t work.
how can i overcome this problem
many thanks.
First as @Raymond Camden said make sure your url is white listed in the .plist. Second it is perfectly normal for you to get a status of 0 when doing AJAX from the file:// protocol. Webkit will set the status to 0 because you are doing a cross domain request which in a web browser would be blocked but in a web view, like PhoneGap uses, is perfectly okay. So in this case 0 == 200. Third get rid of eval, if you are returning JSON data use JSON.parse(xmlhttp.responseText) as it is much safer.