我正在寻找一个通过Asp.Net Webmethod使用Typeahead.js的示例。
我已经将来自http://twitter.github.io/typeahead.js/examples/的示例与基本示例一起使用,但我不完全理解如何使用asp.net webmethod实现猎犬功能。
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);
}
任何帮助都是非常感谢的。
发布于 2015-03-01 22:46:52
看起来您可能需要在c#中以查询字符串的形式获取参数。尝试使用return Suggestions.TextAutocomplete(Request.QueryString"param");
https://stackoverflow.com/questions/22736660
复制