Created
November 3, 2023 07:22
-
-
Save mohammadYousefiDev/0ec5cedf73c589702e52fc4306aaaf6b to your computer and use it in GitHub Desktop.
select2 search ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#_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