我正在使用自动完成功能,而我正在使用undefined
。此外,该函数将值返回为字符串,但在文本框值下方显示为undefined
。我从过去3天开始研究这个问题,但它没有用到
........................
C#
public string[] GetCompletionList(string prefixText)
{
RegistrationBAL _rbal = new RegistrationBAL(0);
DataSet ds = new DataSet();
_rbal.LoadByContextSearch(ds, prefixText);
List<string> strDetailIDList = new List<string>();
foreach (DataRow row in ds.Tables[0].Rows)
{
strDetailIDList.Add(row["SearchKey"].ToString());
}
String[] s = strDetailIDList.ToArray(); return s; }
的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">
$(function() {
$(".tb").autocomplete({
source: function(request, response) {
$.ajax({
url: "MyService.asmx/GetCompletionList",
data: "{ 'prefixText': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function(data) { return data; },
success: function(data) {
response($.map(data.d, function(item) {
return {
value: item.SearchKey
}
}))
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1
});
});
</script>