I want the first element of the selectbox to be selected by default when my page loads. It is selected but does not make ajax request. I want it to trigger the 'select2: select' event. Only the selected part in selectbox changes, it doesn't execute the ajax request. I want it to work like 'select2: select' when I assign the first element. So when I select the first element, it should be triggered in the ajax request.
// 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
})
})