Jquery 我们应该为自动完成ajax代码中的url写些什么?
我们应该为自动完成ajax代码中的url写些什么?我应该写那一页的地址吗?这部分中的GetCategory是什么Jquery 我们应该为自动完成ajax代码中的url写些什么?,jquery,asp.net,ajax,autocomplete,Jquery,Asp.net,Ajax,Autocomplete,我们应该为自动完成ajax代码中的url写些什么?我应该写那一页的地址吗?这部分中的GetCategory是什么 <script type="text/javascript"> $(document).ready(function () { $("#txtSearch").autocomplete({ source: function (request, response) { $.aj
<script type="text/javascript">
$(document).ready(function () {
$("#txtSearch").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '<%=ResolveUrl("~/MasterProfile.master/GetCategory") %>',
data: "{'term':'" + $("#txtSearch").val() + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
});
</script>
您需要提供一个指向端点的URL,该端点将以jQuery Auto Complete期望的格式返回数据,如中所述 该端点可以采取许多不同的形式。您可以使用WebMethods或PageMethods,这与您的问题最为相似。但是微软。您可以使用,但如果这是您将使用它的唯一用途之一,那么这可能会有点过头。所以我建议您使用泛型处理程序.ashx 在站点中添加一个通用处理程序,我们将其称为AutoComplete.ashx,并假设它位于站点的根目录下。下面是一个实现:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write("['testing','more testing','John Doe']");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
url: '<%=ResolveUrl("~/AutoComplete.ashx") %>',