Can The Default "Term" Name Passed In The "jquery UI Autocomplete" Feature Be Changed?
I am trying to change the 'term' field that is set to that by default with the jquery ui autocomplete feature. Is it possibly to easily change it to 'q' (query) without going and c
Solution 1:
Yes, it's possible by making your own AJAX request.
Assume you have the following setup:
$("#myfield").autocomplete({
source: '/my_url/myservice.xyz'
});
Autocomplete by default (as you noticed) sends requests that look like:
myservice.xyz?term=abc"
You can supply a function reference to the source
option of autocomplete. Inside that function you can make your own AJAX request, which would look like this:
$("#myfield").autocomplete({
source: function (request, response) {
// request.term is the term searched for.
// response is the callback function you must call to update the autocomplete's
// suggestion list.
$.ajax({
url: "/my_url/myservice.xyz",
data: { q: request.term },
dataType: "json",
success: response,
error: function () {
response([]);
}
});
});
});
This should generate a request looking more like:
myservice.xyz?q=abc
Solution 2:
You could use the callback source
option and make your own request.
Post a Comment for "Can The Default "Term" Name Passed In The "jquery UI Autocomplete" Feature Be Changed?"