开发者

Return result from a form submit into an iframe in cakephp

How to return the results from the submission of a form to an iframe in cakephp?

Another question is, how to return some message to iframe for every iteration over the loop of a controller action. lets say it iterates for 10 times, so after every iteration, it will i开发者_运维百科mmediately show message like"iteration 1 completed" and so on... in the iframe....


I think you need to look at an AJAX approach to this. You can use Javascript to poke data into the iframe, but iterative interaction between the view and the controller is best done with an AJAX connection.

This is a quick and dirty approach I took. At the end of the controller action:

    App::import('Helper', 'Javascript');
    $javascript = new JavascriptHelper();

    echo($javascript->object($returnVals)); // allows passing of array
    exit(1);

In the view, you need to capture the returned value and parse using JSON.parse:

<snip-->
        if(xmlHttp)
        {
            xmlHttp.open("POST",actionURL,true);
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.onreadystatechange = function()
            {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
        {
            doAction(xmlHttp.responseText,zone);
        }
<--snip>
    function doAction(props,zone)
    {
        var newProps = JSON.parse(props);//needs to be parsed into a JS object.
        //other stuff here
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜