2010-11-26 8 views
0

私はASP.NETページでJQuery AutoCompleteを使用しています。そして、私はashxファイルを使用してリストを作成しています。JQueryオートコンプリートが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

JSONデータを返すASHXに設定されたMIMEコンテンツタイプ。

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

また、ソースをオートコンプリートするデータ型としてjsonを指定します。

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