2012-10-26 59 views
0

我对phonegap非常陌生。我在xcode4.5中安装了phonegap2.1.0。现在phonegap工作正常。但是,我怎样才能调用Web服务,并得到一个JSON响应phonegap?我的代码在下面,但它不起作用。有谁能够帮助我?如何使用phonegap调用webservice并获取json响应iphone

$(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

不写成功:成功:只是成功: – Mehmet

+0

尝试成功:函数(味精,textStatus,jqXHR)...像穆罕默德建议。 如果你仍然有问题看看你的控制台,你有任何错误? – F481

+0

@Mehmet谢谢。 – sathis

回答

0

这是因为你使用的是“本地主机”当你在一个设备/模拟器,然后运行该代码“本地主机”是指设备/模拟器本身,而不是包含您的轨道API的Web服务器。您需要将“localhost”切换到您的服务器的IP地址或主机名。

相关问题