I am trying to integrate an AJAX search function but I am having trouble getting the Zend Framework portion right. I have the following Controller and Action.
class IndexController extends Zend_Controller_Action
{
public function indexSearchAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if ($this->getRequest()->isXmlHttpRequest()) {
if ($this->getRequest()->isPost()) {
$search = new Model_Index();
$this->_helper->json($search->indexSearch());
$this->view->indexSearch = $result;
}
} else {
//regular controller logic goes here
echo "regular controller";
}
}
Copy of my Ajax call is as follows:
$.ajax({
type: "POST",
url: "/index/index-search/format/json",
data: dataString,
dataType: "json",
cache: false,
success: function(html)
{
I just want the model to return a simple message to ensure that it is working up to this point. with that said, here is a copy of my function in the model:
public function indexSearch()
{
$testMessage = "this was returned via ajax";
return $testMessage;
}
Code that triggers the Ajax call:
$(document).ready(function(){
$(".search").keyup(function()
{
var searchbox = $(this).val();
var dataString = 'searchword='+ searchbox;
if(searchbox=='')
{
}
else
{
$.ajax({
type: "POST",
url: "/index/index-search/format/json",
data: dataString,
dataType: "json",
cache: false,
success: function(html)
{
$("#display").html(html).show();
}
});
}
return false;
});
});
I dont know what I am missing, this is my first attempt to getting AJAX calls to work in ZF2 and its not working out.
Any help would be greatly appreciated! cheers!