jQuery的自动完成.NET的WebMethod [英] Jquery autocomplete .NET WebMethod
问题描述
我有jQuery的自动完成一个HttpHandler的工作 - .ashx的文件。它工作得很好,我想知道是否有使用自动完成,在后面的code一[的WebMethod]正确的一个简单的方法 - 以及是否有任何优势吗?
I have Jquery autocomplete working with a HttpHandler - .ashx file. It works fine, I am wondering is there an easy way to use the autocomplete with a [WebMethod] right in the code behind - and are there any advantages to this?
推荐答案
中的HttpHandler和Web服务来执行相同的,
两种实现
然而,我preFER HttpHandler的,因为它是轻量级的,
在另一边的Web服务连接codeS要求和放大器;这增加了额外的负载响应XML数据。
Both implementations of HttpHandler and Web-Services perform identically,
however I prefer HttpHandler as it is lightweight,
on the other side a web-service encodes request & response xml data which adds extra payload.
POP jQueryUI的自动完成与网络的方法:
<一href=\"http://blog.nitinsawant.com/2011/09/integrating-jquery-ui-autocomplete-in.html\">http://blog.nitinsawant.com/2011/09/integrating-jquery-ui-autocomplete-in.html
POP JqueryUI Autocomplete with web-methods:
http://blog.nitinsawant.com/2011/09/integrating-jquery-ui-autocomplete-in.html
JS:
$(document).ready(function () {
$("#<%=txtAutoComplete.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: "webservice/TestService.asmx/SearchData",
data: "{ 'q': '" + request.term + "', 'limit': '10' }",
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 {
label: item.Name,
value: item.id + ""
}
}))
}
});
}
});
});
C#:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public List<tdata> SearchData(string q, int limit)
{
return new List<tdata> { new tdata { id = 0, name = "nitin" } };
}
这篇关于jQuery的自动完成.NET的WebMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!