php - Trigger Zend FlashMessenger in jQuery -


i'm facing issue , wondering if point me in right direction.

i using zend's flashmessenger in controllers, in 1 of files handle forms via ajax posts. thought humane-flatty nice replacement zend flashmessenger in case, layout of different.

is there way trigger zend flashmessenger in ajax post?

this how call zend flashmessenger in controllers:

$this->_helper->flashmessenger(array('success' => 'succesfully added')); 

this jquery:

if (data.weight !== '' && data.customer != '') {    $.ajax({      type: 'post',      url: '/index/line',      data: data,      success: function(res) {        $('#open_orders').append(res);        flashsucces.log('orderline succesfully added.');        //can call zend flashmessenger here?      }    }); } 

the trick answer lies @ view scripts (*.phtml files).

i assuming following index.phtml file view script of indexcontroller file prints form , execute ajax. when click button 'get external content', result of ajax response /index/line controller populated in div1 tag.

    <!doctype html>     <html>     <head>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>     <script>     $(document).ready(function(){         $("button").click(function(){              $.ajax({url: '/index/line',                  success: function(res){                 $("#div1").html(res);                 //your flashmessenger execute here ajax success.             }         });         });     });     </script>     </head>     <body> <?php // print form controller here. echo $this->form; ?>     <div id="div1">let jquery ajax change text</div>     <button>get external content</button>     </body>     </html> 

the above code fetch result lineaction @ indexcontroller ('/index/line'). add following lines @ indexcontroller.php

public function lineaction()              {           $this->_helper->flashmessenger('succesfully added');            if ($this->_helper->flashmessenger->hasmessages())            {$this->view->messages = $this->_helper->flashmessenger->getmessages();}             } 

now call view script of line action (line.phtml). add following lines in line.phtml

<?php   if ($this->messages!=null)             { $messages = $this->messages;                 foreach($messages $message) {                 echo '<script> alert("'.$message.'") </script>';              }             } 

now execute code. ajax execute zend flashmessenger success , display javascript alert message 'succesfully added'.

i have tested above code , works great zend 1.12.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -