php - Jquery Ajax not working with Zend Framework- Json returns parsererror -
php - Jquery Ajax not working with Zend Framework- Json returns parsererror -
i'm new zend framework. here trying array controller jquery ajax function in view. when 'datatype' changed 'json' phone call error.
how send array controller jquery , how receive it. please help
controller
public function init() { $ajaxcontext = $this->_helper->gethelper('ajaxcontext'); $ajaxcontext->addactioncontext('ajax', 'json') ->initcontext(); } public function ajaxaction(){ // other stuff , logic here $results = array( 'return1' => 'value1', 'return2' => 'value2' ); echo $this->_helper->sendjson($results); }
view
$(document).ready(function() { $("#selectoptions").change(function(){ var param1 = 'first'; //or value dom element var param2 = 'second'; //or value dom element $.ajax ({ url: 'index/ajax', contenttype: 'application/json; charset=utf-8', type: 'post', datatype: 'json', async : false, data: {param1: param1, param2:param2 }, success: function(json){ console.log(json); }, error : function(xhr, status){ console.log(status); }, }); }); });
use in controller
$this->_helper->sendjson($results);
or
$this->_helper->json($results);
but without echo
php jquery ajax json zend-framework
Comments
Post a Comment