Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Query Parameter for jQuery UI's Autocomplete

I'm using version 1.8.13 of jQuery UI's Auto complete and by default jQuery is using the query parameter of "?term=" by default, while my app is using "?q=" in the string it is creating. I COULD change the variable to be "term" on the backend, but I'd rather just tell jQuery what the server is trying to send it. Is there a way to change this?

Right now I just have something like this and it works if I change the variable to "term" on the backend, but like I said I wanted to change it to "q" and I can't find any info online about setting the parameter (that works):

$( "#input-search").autocomplete({
   source: "/search/autocomplete/"
});
like image 322
Keith Avatar asked Jul 13 '11 06:07

Keith


People also ask

How pass multiple parameters in jQuery autocomplete?

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. In the source file, you can get the term and additional parameters using the $_GET variable.

How does autocomplete work in jQuery?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.

How can create autocomplete search box in jQuery?

Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })

What is the function of Autocomplete?

Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing. In Android and iOS smartphones, this is called predictive text. In graphical user interfaces, users can typically press the tab key to accept a suggestion or the down arrow key to accept one of several.


1 Answers

You could use the callback form of source and handle all the interaction with the server yourself. Something like this:

$("#input-search").autocomplete({
    source: function(request, response) {
        $.get('/search/autocomplete', { q: request.term }, function(data) {
            response(data.split('\n'));
        });
    }
});
like image 102
mu is too short Avatar answered Sep 22 '22 05:09

mu is too short