我试图一个额外的参数传递给内选择2 Ajax调用:
I'm attempting to pass an extra parameter to an ajax call within select2:
$(".auto-sug").select2({
width:'element',
minimumInputLength:2,
ajax: {
url: "/action/get-custom.php",
data: function (term, page) {
return {
q: term, // search term
page_limit: 10
};
},
results: function (data, page) {
return {results: data.stuff};
}
}
});
其实我是想另一个参数传递给Ajax调用...元素本身的id
I actually want to pass another parameter to the ajax call... the id of the element itself
<input type="text" class="auto-sug" name="custom" id="3383" />
然而
,我无法弄清楚如何实际访问的元素(3383),或在页面上的任何其他值的ID。
however, I'm unable to figure out how to actually access the id of the element (3383) or any other value on the page.
假设有带班自动SUG
,你可以尝试这样的事情多的元素:
Assuming there are multiple elements with class auto-sug
, you could try something like this:
$(".auto-sug").each(function() {
var thisId = this.id;
$(this).select2({
...
ajax: {
...
id: thisId,
},
});
});