I am using select2 version 4.0, and I am trying to make a programmatic selection to a select box which gets its data from an ajax call.
In the documentation, I found how
You can try this.
var dataString = 'id='+$value;
var promise = sendAjaxFunction('load_form.php?k=1',dataString);
$("#LoadMachine").html("");
promise.success(function (data) {
$("#LoadMachine").html(data);
$("#MachineName").select2({
placeholder: 'Select Operation Name ...',
allowClear: true
});
return false;
});
Load the data in a Div #LoadMachine and in result you can load select2.