我有一个 webpart 调用 ASP.NET 处理程序来完成自动完成功能。
ASHX File
<%@ WebHandler Language="C#" Class="MyService.MyAutoComplete" CodeBehind="MyAutoComplete.ashx.cs" %>
代码隐藏文件
namespace MyService
{
/// <summary>
/// Summary description for MyAutoComplete
/// </summary>
public class MyAutoComplete : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var searchTerm = context.Request.QueryString["term"].ToString();
context.Response.Clear();
context.Response.ContentType = "application/json";
var search = GetList();
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string json = jsSerializer.Serialize(search);
context.Response.Write(json);
context.Response.End();
}
}
}
这是我的 JQuery 调用
$(function () {
$("#<%= txtSearchInput.ClientID %>").autocomplete({
source: "/_Layouts/My Service/MyAutoComplete.ashx",
minLength: 2,
select: function (event, ui) {
$(this).val(ui.item.value);
}
});
});
“我的服务”是 webpart 项目中的 SharePoint 布局文件夹。
当我通过 JQuery 进行调用时,它会引发以下错误“无法创建类型'MyService.MyAutoComplete'”
任何帮助表示赞赏。