Ive been developing an application in android with phonegap. can anyone help me on how can i call my webservice that outputs a JSON string through my android application via AJAX with jquery? thank you very much for the help.
I have this piece of code in my Jscript:
$(document).bind("mobileinit", function(){
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
$.ajax({
type: "POST",
timeout: moneTimeout,
url: "http://10.0.2.2:49878/SampleProject.aspx?p_trxn_type=doLogin&p_phoneNumber="+phoneNumber,
error: function (xhr, status, errorThrown)
{
alert(xhr.status);
},
dataType : "json",
cache:false,
async:false,
success: function (ret)
{
try{
var jsonObj = eval('(' + ret + ')');
alert(jsonObj.Contacts.Contact['@phoneNumber']);
alert(jsonObj.Contacts.Contact.LastName);
alert(ret.Contacts.Contact['@phoneNumber'])
alert(ret.Contacts.Contact.LastName);
}
catch(ex){
alert(ex.message);
}
console.log(ret);
alert(ret.length);
alert(ret);
alert(typeof ret);
alert("success");
}
});
and here is the JSON Array the i like to get from my c# webservice,:
{"Contacts":{"Contact":{"@phoneNumber":"0002221111","@countryCode":"1","@typeCode":"73","@type":"Default, Mobile, DefaultContactNumber","@id":"04359c0dcca64638a5fcbb17b386ceed","Salutation":"Mr.","FirstName":"Tom","MiddleName":null,"LastName":"Cruise","NameSuffix":null,"PrimaryAddress":{"Street":{"#cdata-section":"3135 Teodoro Drive"},"Street2":{"#cdata-section":""},"City":{"#cdata-section":"Detroit"},"State":"MS","Country":"US","Postal":"48228"}}}
still im getting an alert: error, and it doesnt display the JSON string array from my c# webservice