gpt4 book ai didi

jquery - 将 Typeahead.js 与 ASP.Net Webmethod 集成

转载 作者:行者123 更新时间:2023-11-30 23:46:14 24 4
gpt4 key购买 nike

我正在寻找将 Typeahead.js 与 Asp.Net Webmethod 结合使用的示例。

我有来自 http://twitter.github.io/typeahead.js/examples/ 的示例使用基本示例,但我不完全理解如何使用 asp.net webmethod 实现 Bloodhound 功能。

TypeAhead 函数正在调用 WebMethod(我可以在调试器中看到该步骤),但 TypeAhead 列表中没有返回任何内容。

这是标记:

<div class="input-group">
<asp:TextBox ID="tboxText" runat="server" CssClass="form-control autocomplete" placeholder="Look Up"></asp:TextBox>
<span class="input-group-btn">
<asp:Button ID="btnAddItem" runat="server" Text="Add" CssClass="btn btn btn-amethyst" />
</span>
</div>

这是 jquery:

$(document).ready(function () {
var textlookup = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '/WebServices/InternalMethods.asmx/TextAutocomplete?param=%QUERY'
});

textlookup.initialize();

$('.autocomplete').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'textlookup',
displayKey: 'value',
source: textlookup.ttAdapter()
});
});

这是 WebMethod:

    [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string> TextAutocomplete(string param)
{
return Suggestions.TextAutocomplete(param);
}

感谢任何帮助。

最佳答案

看起来您可能需要在 C# 中将参数作为查询字符串获取。尝试使用 return Suggestions.TextAutocomplete(Request.QueryString["param"]);

关于jquery - 将 Typeahead.js 与 ASP.Net Webmethod 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22736660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com