views:

277

answers:

1

Can somebody please give an example on passing key value pairs to a jQuery autocomplete list using a webservice.

Tanks for the help.

 $('#txtBox1').autocomplete("Autocomplete.asmx/GetKeyValu", 
{ dataType: "xml", datakey: "string", max: 10, minChars: 0 });



 [WebMethod]
    public Dictionary<string,string> GetKeyValu(string q, int limit)
    {
        Dictionary<string, string> dict = new Dictionary<string, string>();
        dict.Add("key1", "valu1");

        return dict;
    }
A: 

Most browsers cannot directly call a SOAP webservice. Change the WebMethod to a page or IHttpHandler renders Javascript.

void IHttpHander.ProcessRequest( HttpContext context )
{
    Dictionary<string, string> dict = new Dictionary<string, string>();
    dict.Add("key1", "valu1");

    foreach (var key in dict) {
        context.Response.Write( key );
        context.Response.Write( "|" );
        context.Response.Write( dict[key] );
        context.Response.Write( "\n" );
    }
}
Lachlan Roche