[英]How to get data of select2 with POST method
I need to return data of the select2 with POST method.我需要使用 POST 方法返回 select2 的数据。 does anyone have any idea what can I do?有谁知道我能做什么? I tried this but did not even work.我试过这个,但甚至没有工作。
$("#action").select2({ allowHtml: true, ajax: { type: "POST", url: URL, headers: { "Content-Type": "application/json", Authorization: "Bearer " + localStorage.getItem("api_token") }, dataType: "json", data: function(term, page) { console.log(term); return { string: term }; }, processResults: function(data) { console.log(data); return { results: data.map(item => { return { text: item.title, id: item.id }; }) }; } }, allowClear: !0 });
<input class="form-control" id="action">
The code does not even show the log.该代码甚至不显示日志。
The issue was I added input instead of select tag I solve the issue like this问题是我添加了输入而不是选择标签我解决了这样的问题
$("#action").select2({ allowHtml: true, ajax: { type: "POST", url: URL, headers: { "Content-Type": "application/json", Authorization: "Bearer " + localStorage.getItem("api_token") }, dataType: "json", data: function(term, page) { console.log(term); return { string: term }; }, processResults: function(data) { console.log(data); return { results: data.map(item => { return { text: item.title, id: item.id }; }) }; } }, allowClear: !0 });
<select class="form-control" id="action"></select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.