AJAX request results in blank page

I allow users to click on records they own to load them into a session for modification. The records are called "trees" in my project. You can preview a tree in a widget by hovering over its name in a table, so an AJAX request is sent on the onmouseover event.

My problem is that the moment I hover over any name, the entire window goes blank. The layout disappears, and Chrome developer tools shows that the page source has been wiped out. No Javascript error appeared in the console.

I am having trouble understanding why this happens.

This is the view for the tree loading page.

NOTE: All content NOT in the aside clip appears in the .bodytext element the AJAX request is targeting.


<?php

$this->beginClip('aside');


// display table of all available trees.

if (!empty($listing))

{

    echo "<h1>Load Tree</h1>";

    echo "<p>Select a tree to load below.</p>";


    $content = "<tbody>";

    $content .= "<tr><th>Tree Name</th><th>Date Created</th></tr>";

    foreach ($listing as $tree)

    {

        $content .= "<tr>";

        $link     = CHtml::tag('a',array(

            'href'=> $this->createUrl('/tree/load?name='.$tree["name"]),

            'onmouseover'=>CHtml::ajax(array(

                'url'=> $this->createUrl('/index.php'),

                'update'=>'.bodytext',

                'data'=>array(

                    'name'=>$tree["name"],

                    'r'=>'tree/ajax'

                )

            )),            

            ), CHtml::encode($tree["name"]));

        $content .= CHtml::tag('td',array(),$link);

        $content .= CHtml::tag('td',array(),$tree["date_added"]);

        $content .= "</tr>";

    }

    $content.= "</tbody>";


    echo CHtml::tag('table',array('id'=>'availableTrees'),$content);

}

else

{

    echo "<h1>No Trees Available</h1>";

    echo "<p>There are no trees stored on this account!</p><p>Go to the <a href=\"".$this->createUrl('/tree/generator')."\">generator</a> to make your first tree!</p>";

}


$this->endClip();


echo "<h1>Preview</h1>";

$this->widget('application.views.tree.treeWidget', array(

    'session_tree'=>array() // Do not show any tree by default.

));

This handles the AJAX request. I have tried returning and echoing the widget.


<?php

class AjaxLoadAction extends CAction

{

    public function run($name=null)

    {

        $app = Yii::app();

        

        if ($app->user->isGuest)

        {

            throw new CHttpException(403,"You must be logged in to access this resource");

        }


        if ($name == null)

        {

            echo "Tree name not specified.";

        }

        

        $user_id = $app->user->getId();


        $tree = DecisionTreeModel::model()->find("user_id=:user_id AND name=:name",array(":user_id"=>$user_id, ":name"=>$name));

            

        if ($tree == null)

        {

            Yii::log("Failed to load tree: $name under user: $user_id" . $app->user->getId(), "error", "application.controllers.tree" );

            echo "Failed to load tree.";

        }

        else

        {

            $this->controller->widget('application.views.tree.treeWidget',array('session_tree'=>$tree->attributes));

        }

    }    

}

whats this?


'url'=> $this->createUrl('/index.php'),



this is wrong, need controller action here , i think /index , right?

I have tried both /index and /tree/ajax. Both end up with 404s.

I use pretty URLs, but that does not seem to be applying here. Only /index.php removes the 404. Note that my call to CHtml::ajax specifies the route.

You could solve your problem? I’m having the same trouble here.

You must put your logic to handle the ajax request in a controller action.

and as noted above ‘url’=> $this->createUrl(’/index.php’), is very wrong.

name your action actionAjax,put it in tree controller and put url to

/tree/ajax (or /tree/Ajax).