如何使用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
- Phonegap – 在启用自动定位的同时防止旋转?
- webview中的同步Ajax超时
- 在真实设备上的cordova app请求中出现net :: ERR_CONNECTION_TIMED_OUT错误
- 如何在Android中使用youtube应用打开YouTube链接(使用Dreamweaver CS6)?
- backbutton确认退出app android + phonegap + jquery
- 在Android Kitkat上模拟鼠标点击Youtubevideo
- 有了Phonegap,我想录制语音,停止录制,并在Android中播放
- 如何在worklight中使用应用程序内的适配器
- 在Android / PhoneGap上运行的jQueryMobile拒绝.load / .ajax