i am using Ajax Autocomplete for Jquery
( http://www.devbridge.com/projects/autocomplete/jquery/ ) in one of my application. The Search Form looks something lik
All the answers above did NOT work for me (I suspect because I'm passing "POST" data through ajaxSettings variable which might affect "params" but I did not double check).
Anyway all comments gave good hints and I came up with the following:
var data={
'phrase': function() {
return $('#ajax_post').val();
},
'activity_id': function() {
return $('#activity_id').val();
}
}
var options = {
noCache: true,
transformResult: function(response) {
//whatever
},
onSelect: function(suggestion) {
//whatever
},
serviceUrl: "MyPHP.php",
ajaxSettings: {
dataType: "json",
method: "POST",
data: data
}
};
$("#ajax_post").autocomplete(options);
So I was able to deliver to the PHP script both the content of ajax_post and activity_id input fields.
Note that it's not enough to do:
'phrase': $('#ajax_post').val()
Because as mentioned in other answers the value get static.