Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mohammadYousefiDev/0ec5cedf73c589702e52fc4306aaaf6b to your computer and use it in GitHub Desktop.
Save mohammadYousefiDev/0ec5cedf73c589702e52fc4306aaaf6b to your computer and use it in GitHub Desktop.
select2 search ajax
$('#_dlr_select_product').select2({
"language": {
"noResults": function(){
return 'هیچ محصولی یافت نشد!';
},
inputTooShort: function() {
return 'لطفا سه حرف اول عنوان محصول را وارد نمایید';
},
searching: function() {
return "در حال جستجو ...";
}
},
minimumInputLength: 3,
dropdownCssClass: "_dlr_sms_type",
ajax: {
type : "POST",
dataType : "JSON",
url : dlr.home + '/wp-json/api/dlrGetProductsByKey',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', dlr.nonce);
},
data: function (term) {
return {
key: term
};
},
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.title,
id: item.id
}
})
};
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment