javascript - Passing value from Zend controller and fetching it in JS response -


i have ajax call following:

$.post("/user/signindo",{'username':username,"password":password},function(data) { // able have in data object, able access these properties , display them once response there alert(data.id); alert(data.username); alert(data.firstname); } 

and zend controller action:

public function signindoaction() { // doing here values passed view } 

the action doesn't needs return since checks whether login data ok. however, need here somehow in action when response returned javascript, somehow fetches data need work within js script file. how can zend framework? can me out please?

first need ban layout in response. that, put following code in method module::onbootstap() :

public function onbootstrap(mvcevent $e) {     $sharedevents        = $e->getapplication()->geteventmanager()->getsharedmanager();     $sharedevents->attach(__namespace__, 'dispatch', function($e) {         $result = $e->getresult();         if ($result instanceof \zend\view\model\viewmodel) {             // ban layout ajax             $result->setterminal($e->getrequest()->isxmlhttprequest());             // ban layout requests             // set true : $result->setterminal(true);         } else {             throw new \exception('sbmajax\module::onbootstap() result isn't \zend\view\model\viewmodel');         }     }); } 

then in controller build html response :

public function signindoaction() {     // doing here values passed view     return $this->getresponse()->setcontent(json::encode(array(         'data' => ...something,         'success' => 1     )));     // handle errors return response 'success' => 0 } 

personally includes ajax actions in particular module setting entire module :

$result->setterminal(true); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -