Zend:通过JQuery执行错误创建PHP命名空间
示例代码:Zend:通过JQuery执行错误创建PHP命名空间,php,jquery,ajax,zend-framework,Php,Jquery,Ajax,Zend Framework,示例代码: jQuery(function() { jQuery('#changePwYes').click(function(){ <?php $this->session = new Zend_Session_Namespace(Zend_Registry::get('config')->session->nameSpace); $this->session->showBox = "
jQuery(function() {
jQuery('#changePwYes').click(function(){
<?php
$this->session = new Zend_Session_Namespace(Zend_Registry::get('config')->session->nameSpace);
$this->session->showBox = "0";
?>
});
});
jQuery(函数(){
jQuery(“#changePwYes”)。单击(函数(){
});
});
此php脚本应仅在单击按钮时执行,但在加载自身时执行
在这种情况下,当您想从客户端对服务器端进行一些更改而无需页面重定向时,我们有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";
}
是的,会的。因为
php
在jquery执行之前就已经运行了。为了实现动态,您需要使用ajax..php在您的服务器上运行。JavaScript在客户端的web浏览器上运行。你不能这样把它们混在一起。可能是重复的