这是来自.ascx页面,我在这里调用.autocomplete,我正在调用ajax调用。请帮忙。
public class SubClass2Dto extends SuperClass {
在.cs页面上:
$("#txtUsers").autocomplete({
//source: availableTags
source: function (request, response) {
//Pass the selected country to the query manager to limit the selection to 1 country
$.ajax({
url: 'DietitianAppointment.ascx/GetNames',
data: '{Name:' + $('#txtUsers').val() + '}',
type: 'POST', // a jQuery ajax POST transmits in querystring format (key=value&key1=value1) in utf-8
dataType: 'json', //return data in json format
success: function (data) {
response($.map(data, function (item) {
return {
label: item.stateName,
value: item.name
//abbrev: item.stateAbbrev
};
}));
}
});
}
});
答案 0 :(得分:0)
是, 因为您已经在Cs中将方法定义为[WebMethod] 你有这样的ajax调用网址..
url: "/DietitianAppointment.aspx/GetNames"
所以你的Ajax Call会是这样的......
$.ajax({
url: '/DietitianAppointment.aspx/GetNames',
data: '{Name:' + $('#txtUsers').val() + '}',
type: 'POST', // a jQuery ajax POST transmits in querystring format(key=value&key1=value1) in utf-8
dataType: 'json', //return data in json format
success: function (data) {
response($.map(data, function (item) {
return {
label: item.stateName,
value: item.name
//abbrev: item.stateAbbrev
};
}));
}
});
您必须使用 [ScriptService] 属性声明您的Service Cs类
如果您将Web服务用于服务器代码而不是用户控件的CS类,则可以这样写。
[ScriptService]
public class YourCSClass : System.Web.Services.WebService {
[WebMethod]
public static string GetNames(string Name)
{
return "";
}
}