我在我的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