大家好,我是 jquery 的新手,我正处于 jquery 的学习阶段。我正在尝试使用 jquery 创建一个自动完成文本框功能。我在这里遇到错误我不知道如何得到它是什么错误?它只是我的代码到 jquery 代码的错误部分..
这是我的 Jquery 代码
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Home.aspx/GetData",
data: "{'Prefix':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="demo">
<div class="ui-widget">
<label for="tbAuto">Enter UserName: </label>
<input type="text" id="txtSearch" class="autosuggest" />
</div>
这是我的 C# 代码
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetData(string Prefix)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("myconnectionstring"))
{
using (SqlCommand cmd = new SqlCommand("select hotelname from Hm_HotelMaster where hotelname=@hotelname+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@hotelname", Prefix);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["hotelname"].ToString());
}
return result;
}
}
请告诉我为什么它不起作用,我怎样才能得到确切的错误是什么