2010-11-26 95 views
0

我正在使用我的ASP.NET页面上的JQuery自动完成功能。而且,我正在使用ashx文件填充列表。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"); 
    } 
} 

回答

1

设置MIME内容类型为ASHX返回JSON数据。

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

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

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