【发布时间】:2012-08-18 19:05:42
【问题描述】:
我有一个使用数据表从数据库访问值的 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;
}
【问题讨论】:
-
mydbCon是service1.asmx中的方法名吗?可以显示 service1.asmx 的内容吗?
-
我已经添加了我的 service1.asmx 看看
-
stackoverflow.com/a/2979938/169714 你为什么使用
?wsdl? -
我已经删除了 >wsdl 并检查了但没有工作
-
因为你只是返回一个数据表而不是json,所以请使用json.codeplex.com
标签: javascript android jquery jquery-mobile cordova