[英]JQuery UI Autocomplete and Generic Handler (ashx) - C# ASP.NET
I'm trying to use the JQuery Autocomplete, but I guess I am having trouble getting the format it expects from my handler. 我正在尝试使用JQuery Autocomplete,但是我想我在从处理程序中获取期望的格式时遇到了麻烦。
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?
有任何想法吗?
It needs to be in JSON format indeed, here a sample of the general outline I used before: 实际上,它必须采用JSON格式,这是我之前使用的一般概述的示例:
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();
}
The response needs to be in JSON format. 响应必须为JSON格式。 See http://docs.jquery.com/UI/Autocomplete where it discusses using a String that specifies a URL.
请参阅http://docs.jquery.com/UI/Autocomplete ,其中讨论使用指定URL的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.