这是从ajax
调用的web方法[WebMethod]
public Sessions GetGroups(string SearchText)
{
try
{
return (new SessionManager()).AutoCompleteSessions(SearchText);
}
catch (Exception Ex)
{
return new Sessions();
}
}
这是ajax方法
$(document).ready(function () {
$('<%=TxtGroups.ClientID %>').autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '/WebServices/Sortable.asmx/GetGroups',
data: '{SearchText: \'' + '<%=TxtGroups.ClientID %>' + '\'}',
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
});
此处&#39; txtgroups&#39;是一个ASP文本字段,任何文本输入都分配给搜索文本。