我对手机新手很新。我在phonegap2.1.0
中安装了xcode4.5
。现在phonegap工作正常。但是我如何调用web服务并获得json对phonegap的响应?我的代码如下,但它不起作用。有人能帮助我吗?
$(document).ready(function () {
$.ajax({
alert("alert");
url: "http://localhost:55022/WebSite1/sample.asmx/returnEmployees",
data: null,
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg, textStatus, jqXHR){
alert(textStatus);
//var theRealData = msg.d;
/*
$.each(theRealData.employees, function (index, item) {
// at this point, item is an array, since theRealData.employees is an array of arrays
var col1 = item[0];
var col2 = item[1];
alert(col1);
}); */
},error:function(jqXHR, textStatus, errorThrown){
console.log(textStatus +"------" +errorThrown + jqXHR );
// navigator.notification.alert('Server Error');
}
});
});
答案 0 :(得分:0)
这是因为在设备/模拟器上运行此代码时使用的是“localhost”,然后“localhost”指的是设备/模拟器本身,而不是包含rails API的Web服务器。您需要将“localhost”切换为服务器的IP地址或主机名。