hello i try to use ajax and zend in my application , i could pass variable to server
but i can not get data from server , it does not return values,
it return all html code page,
where is my mistake?
$('#myForm').submit(function($e){
$e.preventDefault();
var $paramToServer=$("#myForm").serialize();
$.ajax({
type:'POST',
url:'test',
data:$paramToServer ,
success:function(re){
var res = $.evalJSON(re);
console.log(res.id); // to see in firebog
},
dataType:'json'
});
});
public function testAction() {
// action body
$this->_helper->getHelper('viewRenderer')->setNoRender();
// If you use layout, disable it
Zend_Layout::getMvcInstance()->disableLayout();
$name=$this->getRequest()->getParam ( 'name' ); //pass $name to server
$return = array(
'id' => '5',
'family' => 'hello ',
);
$return = Zend_Json::encode( $return);
// Response
$this->getResponse()->setBody($return);
}