1

I'm trying to use the JQuery Autocomplete, but I guess I am having trouble getting the format it expects from my handler.

Here is what the handler does. This was in another SO question....

 context.Response.ContentType = "text/plain";
 var companies = GetCompanies(); //This returns a list of companies (List<string>)

 foreach (var comp in companies)
 {
     context.Response.Write(comp + Environment.NewLine);
 }

This doesn't work. It is definately getting called and it is returning what I would expect this code to return. Any ideas?

2 Answers 2

6

It needs to be in JSON format indeed, here a sample of the general outline I used before:

    class AutoCompleteEntry
    {
        public int id { get; set; }
        public string label { get; set; }
        public string value { get; set; }
    }

    private void GetAutoCompleteTerms()
    {
        Response.Clear();
        Response.ContentType = "application/json";

        //evaluate input parameters of jquery request here

         List<AutoCompleteEntry> autoCompleteList= new List<AutoCompleteEntry>();
        //populate List of AutocompleteEntry here accordingly

        JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
        string json = jsSerializer.Serialize(autoCompleteList);
        Response.Write(json);
        Response.End();
    }
Sign up to request clarification or add additional context in comments.

Comments

1

The response needs to be in JSON format. See http://docs.jquery.com/UI/Autocomplete where it discusses using a String that specifies a URL.

1 Comment

So then I am assuming stackoverflow.com/questions/305994/… is using a plugin instead of the JQuery UI... OOps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.