我在我的Web表单.net应用程序中使用Select2 4.0.3。我正在尝试使用web服务加载远程数据,但它不像预期的那样工作。使用Select2和Webservice加载远程数据
创刊号现在面临的是WebService的方法是没有得到所谓的和我得到一个控制台错误:
System.InvalidOperationException: Missing parameter: text.
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
所以,我想从Web服务调用
<WebMethod()> _
Public Function GetDataFromService() As String
这样做去除paremeter该方法被解雇,但仍然在select2中的项目没有被填充(屏幕截图已经存在)。
有人能帮我弄清楚我在哪里犯了一个错误。
下面是详细信息:
选择二码在网络表单:
$("#ddlEntity").select2({
ajax: {
url: "Service/InvoiceHTMLService.asmx/GetDataFromService",
type: 'POST',
delay: 250,
params: {
contentType: 'application/json; charset=utf-8'
},
dataType: 'json',
data: function (term, page) {
return {
text: term,
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
WebService Method:
<WebMethod()> _
Public Function GetDataFromService(text As String) As String
Return "{['id':1, 'text':'Test1'],['id':2, 'text':'Test2']}"
End Function
我移除了模板选项,还是两者的问题依然存在,Web服务不会被调用,而不是数据正在被调用 回。 – user2561997
oops响应应该是数组对象返回[{'id':1,'text':'Test1'}, {'id':2,'text':'Test2'}] –
我能够得到数据返回,但是我在帖子中提到的主要问题是,我无法获取使用text参数调用的Web服务方法,如果我保留它为空,它就可以工作。但我需要键入的文本作为参数,以便我可以过滤数据。 – user2561997