代码之家  ›  专栏  ›  技术社区  ›  Jason

JQuery UI自动完成和通用处理程序(ashx)-C#ASP.NET

  •  1
  • Jason  · 技术社区  · 15 年前

    以下是处理程序的操作。这是另一个问题。。。。

     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);
     }
    

    这不管用。它确实被调用了,并且它返回了我希望这段代码返回的内容。有什么想法吗?

    2 回复  |  直到 15 年前
        1
  •  1
  •   Andrew    15 年前

    响应必须采用JSON格式。见 http://docs.jquery.com/UI/Autocomplete 其中讨论了如何使用指定URL的字符串。

        2
  •  6
  •   BrokenGlass    15 年前

        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();
        }