JQuery 自动完成无法与 ashx 一起使用

发布于 2024-10-04 05:24:55 字数 573 浏览 0 评论 0原文

我正在我的 ASP.NET 页面上使用 JQuery AutoComplete。而且,我使用 ashx 文件来填充列表。

但是,ashx 看起来并没有发射。我不确定我做错了什么。

jQuery 代码

$(function () {
    $("#<%=txtBox.ClientID%>").autocomplete('MyList.ashx', { minChars: 1 });
});

.ashx 代码

[WebService(Namespace = "http://www.yoursite.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
public class MyList: IHttpHandler
{ 
    public void ProcessRequest(HttpContext context) {
        //Just to test
        context.Response.Write("test");
    }
}

I am working on JQuery AutoComplete on my ASP.NET page. And, I am using ashx file to populate list.

But, the ashx looks like it's not firing. I am not sure what I am doing wrong.

jQuery code

$(function () {
    $("#<%=txtBox.ClientID%>").autocomplete('MyList.ashx', { minChars: 1 });
});

.ashx code

[WebService(Namespace = "http://www.yoursite.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
public class MyList: IHttpHandler
{ 
    public void ProcessRequest(HttpContext context) {
        //Just to test
        context.Response.Write("test");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-10-11 05:24:55

设置 ashx 的 MIME 内容类型以返回 json 数据。

Response.ContentType = "application/json";
Response.Write("['Content1', 'Content2']");  //consider using JsonSerializer

另外,指定 json 作为源自动完成的数据类型。

$("...").autocomplete('MyList.ashx', { dataType: "json" });

Set MIME content-type for the ashx to return json data.

Response.ContentType = "application/json";
Response.Write("['Content1', 'Content2']");  //consider using JsonSerializer

Also, specify json as the data type for the source to autocomplete.

$("...").autocomplete('MyList.ashx', { dataType: "json" });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文