입력 유형 텍스트에이 기능을 적용했지만 작동하지 않습니다. 내가 잘못 가고있는 곳을 알려주는 지침이 필요합니다. 이 자바 스크립트 코드와 작동하지 않습니다 :자동 완성 기능이 작동하지 않습니다. 도움이 필요합니다.
$(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를 어떤 종류의 파일을 추가해야합니까?
완벽하게 잘 작동? 웹 메소드가 호출되지 않았습니까? 오류가 있습니까? –
아니요 어떤 오류도 발생하지 않지만 자동 완성 기능이 작동하지 않습니다. 전체 코드 –
이 제출 된 이유는 어디에서 문제인지 알지 못합니다. 'getReason' 메서드가 호출되는 이유는 무엇입니까? 'null'이 아닌 다른 것을 반환합니까? – Yoav