jQuery autocomplete plugin sent request like this
mysite.com/suggestion?term=Sadegh
is there any way to change term querystring key to another? i can't find option that provide this for me ;)
The above is not correct for the current release (1.8.6). Not sure if it ever was...
$(...).autocomplete({
source: function(request, response) {
$.getJSON("url", { foo: request.term }, response);
}
});
foo: being the new param key name..
I assume you're using jQuery UI AutoComplete
You need to provide a callback as the source, like this:
$(...).autocomplete({
source: function(term, callback) {
$.getJSON("url", { foo: term }, callback);
}
});
Actually I dug up the code that the plugin uses. Adapting it to change the term would be something like this:
$('#form').autocomplete({
source: (function() {
var xhr;
return function(request, response) {
if (xhr) {
xhr.abort();
}
xhr = $.ajax({
url: 'mysite.com/suggestion',
data: {
foo: request.term
},
dataType: 'json',
success: function(data) {
response(data);
},
error: function() {
response([]);
}
});
}
})()
});
I would say this has 2 advantages:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With