代码如下:
代码如下:
代码如下:
代码如下:
var url = "serviceHandler.ashx";
$("#auto").autocomplete(
{
source: url
}
);
代码如下:
public class serviceHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
HttpResponse response = context.Response;
System.IO.TextWriter writer = response.Output;
// 注意,必须是标准的 JSON 格式串,必须使用双引号
writer.Write("[\"One\", \"Two\", \"Three\"]");
}
public bool IsReusable {
get {
return false;
}
}
}
代码如下:
var url = "serviceHandler.ashx";
$("#auto").autocomplete(
{
source: url,
minLength: 2
}
);
代码如下:
$(function () {
var url = "serviceHandler.ashx";
var cache = {}, lastXhr;
$("#auto").autocomplete({
minLength: 2,
source: function (request, response) {
var term = request.term;
if (term in cache) {
response(cache[term]);
return;
}
lastXhr = $.getJSON(url, request, function (data, status, xhr) {
cache[term] = data;
if (xhr === lastXhr) {
response(data);
}
});
}
});
}
);