Answers for "select2 ajax method"

2

select2.org events

$('#mySelect2').on('select2:select', function (e) {
    var data = e.params.data;
    console.log(data);
});
Posted by: Guest on July-20-2020
4

select2 server side

$('#payment_method').select2({
	placeholder: 'Select a option',
	ajax: {
			url: 'ajax_get_url',
            dataType: 'json',
            type: 'GET',
            processResults({ data }) {
				return {
					results: $.map(data, function (item) {
						return {
							text: item.name,
                            id: item.id,
                            }
						})
					}
				}
			}
		});
Posted by: Guest on July-16-2020

Browse Popular Code Answers by Language