I have this call:
bindAutoComplete('pro_title');
which uses this function to make an jQuery AJAX call:
function bindAutoComplete(id) {
$("#" + id).keyup(function() {
if (this.value.length > 1) {
$.post("/ajax/autocomplete" , {id: this.value }, function(data) {
// do stuff here...
});
}
});
}
which works with this PHP script:
public function autocompleteAction()
{
if ($this->getRequest()->isPost()) {
echo print_r($this->getRequest()->getPost());
}
}
When I run these scripts, PHP echoes:
Array ([id] => test) 1
where ‘test’ in this case is the value in this.value from the AJAX call.
What I am looking for is [id] to be replaced with pro_title.
Please help!
The {id: this.value } should be {id: id }..
If you want to send the value as well you can do {id: id, value: this.value }