How to pass additional parameters in jQuery UI Autocomplete

At the time of using jQuery UI Autocomplete in PHP, many times you need to pass additional parameters to an autoComplete call. Here is a simple way to pass extra parameters to the source URL. In that case, you need to define a callback function to the source option of autoComplete call. Also, you can pass multiple parameters using this approach. Your jQuery UI Autocomplete function would be like the following.

<script>
$(function() {
    $( "#skills" ).autocomplete({
        source: function(request, response) {
            $.getJSON(
                "search.php",
                { term:request.term, extraParams:$('#extra_param_field').val() }, 
                response
            );
        },
        minLength: 2,
        select: function(event, ui){
            //On select action
        }
    });
});
</script>

In the source file, you can get the term and additional parameters using the $_GET variable.

$term $_GET['term'];
$extraVar $_GET['extraParams'];

10 Comments

  1. Nick Said...
  2. Pooja Said...
  3. Marane Toyane Said...
  4. Shums Said...
  5. Reform Said...
  6. Amit Kumar Said...
  7. ♥ Said...
  8. Javier Said...
  9. Anurag Said...
  10. Adnan Said...

Leave a reply

keyboard_double_arrow_up