0

I have this code, how can I pass a parameter to data.php (data.php?q=) so when user digits something I can filter the data and retrieve just a subset of records?

var company;

$(document).ready(function() {

$('.select-ajax').multiselect({
    maxHeight: 400,
    buttonWidth: '100%',
    includeSelectAllOption: true,
    enableFiltering: true
}); 

$.ajax({
  type: 'GET',
  url: '/data.php',
  dataType: 'json',
  success: function(data) {
     $.each(data, function (i, item) {
         company = item.company;
         $('.select-ajax').append('<option value="' + item.company + '">' + item.company + '</option>');
         console.log(item)
    });
    $('.select-ajax').multiselect('rebuild');
  },
  error: function() {
        alert('error loading items');
  }
 });

$('.select-ajax').trigger( 'change' );

}); 
</script>```
  • The `data` parameter of the [jQuery ajax settings](https://api.jquery.com/jquery.ajax/) object will append to the URL if it's a GET request. You'll need an event handler to obtain the filter value. I suppose the plugin you're using would have defined a hook to let you do that. Otherwise, do a `.on("change", function(e) { } )` – Jasen Mar 07 '22 at 18:28
  • 1
    Does this answer your question? [How to pass parameters in GET requests with jQuery](https://stackoverflow.com/questions/15576548/how-to-pass-parameters-in-get-requests-with-jquery) – Jasen Mar 07 '22 at 18:30

0 Answers0