0

サンプルコード:

jQuery(function() {
    jQuery('#changePwYes').click(function(){
        <?php 
            $this->session = new Zend_Session_Namespace(Zend_Registry::get('config')->session->nameSpace);
            $this->session->showBox = "0";
        ?>
    });

});

このphpスクリプトは、ボタンがクリックされたときにのみ実行されますが、それ自体のロード中に実行されます。

何をすべきか

4

1 に答える 1

2

このような場合、ページのリダイレクトを行わずに、クライアント側からサーバー側で何らかの変更を加えたい場合に、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);
         }
        });
    });
});

controllerで、新しいactionを作成します。

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";    
}
于 2013-01-18T07:37:14.127 に答える