在这种情况下,当您想从客户端在服务器端进行一些更改而不进行页面重定向时,我们有AJAX。
通过AJAX从您的点击事件中调用Zend 控制器操作:
jQuery(function() {
jQuery('#changePwYes').click(function(){
$.ajax({
url: "myApp/public/index.php/controller-name/create-name-space/format/html",
type: "POST",
data:{mydata : 'test'}
success: function(html){
alert('Done');
},
error: function(jqXHR, textStatus, errorThrown){
alert('An error occurred);
}
});
});
});
在您的控制器中,创建一个新操作:
public function createNameSpaceAction()
{
//Disable the layout rendering for the ajax request
$this->_helper->layout->disableLayout();
//Set no renderer in this case
$this->_helper->viewRenderer->setNoRender(true);
//Retrieve dada if needed
$myData = $_POST['mydata'];
$session = new Zend_Session_Namespace(Zend_Registry::get('config')->session->nameSpace);
$session->showBox = "0";
}