jQuery UI的自动完成与asp.net工作 [英] Jquery UI AutoComplete not working with asp.net
本文介绍了jQuery UI的自动完成与asp.net工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的jQuery的:
This is my Jquery:
$("#completeMe").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Main.aspx/GetAutocomplete",
type: "POST",
dataType: "json",
data: Data,
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data, function (item) {
return { value: item };
}))
}
})
}
});
这是我的Main.aspx.cs:
This is my Main.aspx.cs:
[System.Web.Services.WebMethod]
public static List<string> GetAutocomplete(string cityName)
{
List<string> City = new List<string>() { "hh", "hh1" };
return City;
}
现在这工作,当我返回,而不是名单的字符串。但是当我使用它像这样用列表我得到:
Now this works when i return string instead of List. But when I use it like this with List I get:
未捕获类型错误:未定义不是一个函数的jQuery-ui.min.js:9 ...
Uncaught TypeError: undefined is not a function jquery-ui.min.js:9...
我不明白,这个方案似乎工作的许多人在网上,也许它是与我的jquery / UI版本?我使用jQuery的1.7.1.min和jQuery的UI最新版本。
I don't understand, this solution seem to work to many people on web, maybe it has something to do with my jquery/ui versions? I am using jquery 1.7.1.min and jquery-ui latest version.
推荐答案
更改您的成功函数像这样
Change your success function like this
success: function (data) {
response($.map(data.d, function (item) {
return { value: item };
}))
数据包含在 data.d
属性。
这篇关于jQuery UI的自动完成与asp.net工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文