我有一個asp.net web服務從數據庫訪問值使用數據表 和我的JavaScript在eclipse中是這樣的,它使用phonegap在android模擬器中運行,但是這個代碼似乎不工作.pls幫助我。如何在android中使用phonegap調用asp.net webservice
<script type="text/javascript">
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");
}
});
}
</script>
和我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;
}
是mydbCon service1.asmx中的方法名稱?你可以顯示service1.asmx的內容嗎? –
我已經添加了我的service1.asmx檢查出來 – dennis
http://stackoverflow.com/a/2979938/169714以及爲什麼使用'?wsdl'? –