select2 search of json results not working select2 search of json results not working wordpress wordpress

select2 search of json results not working


You do not appear to have any code in your server side code for filtering and paginating results. Select2 realizes that it's more efficient for this to be done on the server side and expects developers to implement it there. The search term will be passed in as q and the page will be passed in as page (if it's available).

If you do not want to implement searching and pagination on the server side, or only have an endpoint which returns all results, you can still work around it. You just need to initialize Select2 with the JSON results as data instead of using the AJAX functionality.

$.ajax({  url: "_bpl_content/bpl_content.php",  type: 'POST',  contentType: 'application/json; charset=utf-8'}).then(function (response) {  $(".js-data-example-ajax").select2({    placeholder: "Select a Review",    minimumInputLength: 3,    data: response  });  });