我正在用PhoneGap在Android中開發本機應用程序。並且我已經在Visual Studio(c#)中創建了一個Websevice,它將返回一個XML片段。所以我已經將返回的XML值轉換爲JSON,並在Mozilla Firefox中進行了測試。但是當我試圖用JQuery來調用AJAX的Webservice時。我試着編碼一個警報消息,它將返回服務的數據。但它似乎不返回任何數據。任何人都可以請幫助我嗎?感謝使用PhoneGap的JQuery for Android應用程序的Ajax
這裏是我的代碼:
$.ajax({
type: "POST",
url: "http://10.0.2.2:49878/a.aspx?p_trxn_type=doLogin&p_phoneNumber="+phoneNumber,
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert("error");
},
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");
}
});
您是否獲得在控制檯中的任何錯誤? 你能列出他們嗎? – sirmdawg 2012-04-20 14:07:56
警報「錯誤」是我得到的。 -_- – Newbie 2012-04-20 14:15:09
它警告textStatus和errorThrown,而不是隻是「錯誤」 也嘗試使用: console.log(errorThrown); console.log(textStatus); – sirmdawg 2012-04-20 16:49:08