English 中文(简体)
Ajax与Zendframework
原标题:Ajax with Zendframework

朋友

我如何把Ajax与冻结框架结合起来。 我需要一些良好的辅导。

问题回答

把这个放到你的控制器中。

public function init()
{
    $contextSwitch = $this->_helper->getHelper( contextSwitch );
    $contextSwitch->addActionContext( test ,  json )
                  ->initContext();
}

创建一个测试动作 (Créer un test d'action)

public function testAction()
{
    $this->view->var1 = "I m testing";
}

然后在您的视图中使用 jQuery 进行请求。

<script type="text/javascript">

$(document).ready(function(){
    $( #display ).ajaxStart(function(){
        $(this).html( Loading... );   
    });

    str = $( #test ).val();
    $( #link ).bind( click ,function(event){
        event.preventDefault();
        $.post(
        this.href,
        { var1: str, format:  json  }, 
        function(data){
            $( #display ).html(data.var1);
        },
        "json"
        );          

    });

});

</script>
<input type="text" name="test" id="test" value="just testing" />
<p>
    <a href="<?php echo $this->url(array( controller  =>  index ,  action  =>  test )); ?>" id="link">Testar</a>
</p>

<div id="display">...</div>

你可以在你的控制器中使用类似这样的东西:

    public function testAction() {
        // Remove all of your HTML stuff
        $this->_helper->layout->disableLayout();
        // PHP to create an array form database or something
        // This will return the info as json. It takes care of the header and everything else!
        return $this->_helper->json->sendJson( array( test ) );
    }




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签