我已将其应用于输入类型的文本,但它不起作用。我需要一些指导来告诉我哪里出错了。这是 javascript 代码,无法正常工作:
$(document).ready(function () {
$('#reasondescriptiontxtbox').autocomplete( {
source: function (request, response) {
$.ajax( {
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/getReason",
data: "{'keywords':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data) {
response(data.d);
},
error: function (result) {
//alert("Error");
}
});
},
minLength: 2
});
});
后面的代码:
[WebMethod]
public static IList<string> getReason(string keywords)
{
int count = 0;
IList<string> result = new List<string>();
string constr
= System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection con1 = new SqlConnection(constr);
SqlCommand cmd1 = con1.CreateCommand();
cmd1.CommandText = "select distinct Code_Description from CODE_DESCRIPTION_277 where Code_Description '%" + keywords + "%'";
try
{
con1.Open();
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
count++;
result.Add(dr["Code_Description"].ToString());
if (count == 100)
break;
}
con1.Close();
return result;
}
catch
{
return null;
}
}
我必须添加某种 jQuery 文件吗?