我有一个 asp.net Web 服务使用数据表从数据库访问值,我的 javascript 在 eclipse 中像这样运行,它使用 phonegap 在 android 模拟器中运行,但这段代码似乎不起作用。请帮帮我。
<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;
}