I'm facing an issue and I was wondering if someone could point me in the right direction.
I am using Zend's FlashMessenger in my controllers, but in one of my files I handle my forms via AJAX posts. I thought Humane-flatty would be a nice replacement for Zend FlashMessenger in that case, but the layout of it is completely different.
Is there any way to trigger Zend Flashmessenger in my AJAX post?
This is how I currently call Zend FlashMessenger in my controllers:
$this->_helper->FlashMessenger(array('success' => 'Succesfully added'));
This is my 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 I call Zend flashmessenger from here?
}
});
}
I suppose your URL, function line in your index controller "index/line", returns some JSON/XML or some HTML which you return and append into a div with #open_orders id.
The idea is, your ajax call needs to return a function from your controller which calls your FlashMessenger call,
$this->_helper->FlashMessenger(array('success' => 'Succesfully added'));
In other words that code needs to run from your controller, and returned to your client (callback of your ajax call in your jquery statemtent) via a direct call.
You may either return partial responses from your "res" and split them and append the correct part into your div, and the other part you append to a preceding div with a different id, so that your injected FlashMessenger code works,
OR
Where you have the following comment
//Can I call Zend flashmessenger from here?
you call another ajax call to another function in your controller where you call the FlashMessenger code in that function, so that you call both your required bits and the FlashMessenger
TLDR: You need that FlashMessenger call in your Zend(Server) side, and call that function in your controller from your client via the .ajax call
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With