如何使用phonegap在android中调用asp.net webservice

我有一个asp.net Web服务使用数据表从数据库访问值,我的javascript在eclipse中就像这样在android模拟器中使用phonegap运行,但这段代码似乎不起作用.pls帮助我。

 function GetAge() { jQuery.support.cors = true; $.mobile.allowCrossDomainPages = true; $.ajax({ data: datas, type: "POST", async: false, dataType: "json", contentType: "application/json; charset=utf-8", url: "http://localhost:50113/Service1.asmx/mydbCon?wsdl", success: function (msg) { $('#divToBeWorkedOn').html(msg.text); }, error: function (e) { $('#divToBeWorkedOn').html("unavailable"); } }); }  

我的service1.asmx是这样的

 [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public DataTable mydbCon() { SqlConnection SqlCon = new SqlConnection(""); SqlCon.Open(); SqlCommand SqlComm = new SqlCommand(); SqlComm.Connection = SqlCon; SqlComm.CommandType = CommandType.Text; SqlComm.CommandText = "select password from tbl_login where username='aby';"; DataTable EmployeeDt = new DataTable("tbl_login"); SqlDataAdapter SqlDa = new SqlDataAdapter(SqlComm); SqlDa.Fill(EmployeeDt); return EmployeeDt; } 

使用包管理器控制台或对话框将Json.Net添加到您的解决方案中

然后:

 [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string mydbCon() { SqlConnection SqlCon = new SqlConnection(""); SqlCon.Open(); SqlCommand SqlComm = new SqlCommand(); SqlComm.Connection = SqlCon; SqlComm.CommandType = CommandType.Text; SqlComm.CommandText = "select password from tbl_login where username='aby';"; DataTable EmployeeDt = new DataTable("tbl_login"); SqlDataAdapter SqlDa = new SqlDataAdapter(SqlComm); SqlDa.Fill(EmployeeDt); return JsonConvert.SerializeObject(EmployeeDt, Formatting.Indented); } 

这是json.Net在nuget画廊上的链接: http ://nuget.org/packages/Newtonsoft.Json