Jquery自动完成Ajax ASP.NET -什么也没发生
本文关键字:什么 NET ASP Ajax Jquery | 更新日期: 2023-09-27 18:16:31
我不能让我的Jquery UI自动完成工作。编辑:我将列表解析为json,并在调试时获得json,但我的自动完成没有响应,文本框下没有任何内容,也没有errormessage
我有。net 4.5
<script type="text/javascript">
$( document ).ready(function() {
$(function () {
$(".tags").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../SearchService/Search.ashx?term=" + request.term,
data: {},
dataType: "json",
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('error');
},
success: function (data) {
console.log('YES');
response($.map(data.d, function (item) {
return {
value: item.dataFromServer
}
}))
}
});
}
});
});
});
</script>
服务(编辑序列化json)
public void ProcessRequest(HttpContext context)
{
string searchstring = context.Request.QueryString["term"]!= null ? context.Request.QueryString["term"] : string.Empty;
//string searchstring = "Ögon";
if (!String.IsNullOrEmpty(searchstring))
{
context.Response.ContentType = "text/json";
context.Response.Write(GetJSON(ProductSearch(searchstring)));
}
}
public List<String> ProductSearch(string searchstring)
{
LinqtoDBDataContext db = new LinqtoDBDataContext();
var searchresult = db.SearchCatalog(searchstring);
List<string> list = new List<string>();
foreach (var item in searchresult)
{
list.Add(item.SearchOut);
}
return list;
}
public static string GetJSON(object obj)
{
var oSerializer = new JavaScriptSerializer();
var sbJsonResults = new StringBuilder();
oSerializer.Serialize(obj, sbJsonResults);
return sbJsonResults.ToString();
}
你错过了成功功能吗?
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item.dataFromServer
}
}))
},