我希望在我的页面加载时默认选择下拉框的第一个元素。它已被选中,但不会发出AJAX请求。我希望它触发“select2:select”事件。只有下拉框中选定的部分会更改,不会执行AJAX请求。当我指定第一个元素时,我希望它像“select2:select”一样工作。因此,当我选择第一个元素时,它应该触发AJAX请求。
// the part where I select the first element by default. The part that doesn't work as I want
$('select[name=items]').prop('selectedIndex', 1).trigger('change.select2');
// For event being selected in selectboxt
$('select[name=items]').on('select2:select', function (e) {
$.ajax({
"url":'myendpoint',
"headers": {
},
"method": "GET",
"success": function (data) {
//my operations
})
})
e.params.data
来获取所选值吗?你可以像这样传递所选值和其他值。 - Swati