problem in return value from server to client in ajax
- by user1400
hello i try to use ajax and zend framework 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() {
$this->_helper->getHelper('viewRenderer')->setNoRender();
//disable layout
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);
}