Ajax Auto Refresh Div

Hi I’m new to Yii and I had a problem with my code.

This is my views file Display.php




<script>

var auto_refresh = setInterval(

function()

{

$('#myDIV').fadeOut('slow').load('MyController.php').fadeIn("slow");

}, 5000);

</script>




    <div id="myDIV" >

        <div>Latest Count: <?php echo $db[0]['TotalCount'];?></div>

        <div>Latest EmpID: <?php echo $db[0]['EmpID'];?></div>

   

    </div>






This is where my models file DailyResultAction.php







<?php if ( ! defined('YII_PATH')) exit('No direct script access allowed');

define("MainDB","MyDB");


class  DailyResultAction{

    

 

    public function  GETResultQuery(){

        $mysql = new TestMYSQL();

        $sqlstr = "Select *,(select count(*) from myTable) as TotalCount from ".MainDB.".myTable where EmpID=(select max(EmpID) from ".MainDB.".myTable)";

        

        $result = $mysql->MyQueryAll(MainDB,$sqlstr);

        unset($mysql);

        return $result;              

    }

    




This is my controller file MyController.php




<?php




class MyController extends Controller

{

    

    public function ControllerResult()

    {

        

            

            $this->layout='myLayout';

            

            $Display= new DailyResultAction();

            $model =  $Display->GETResultQuery();

            $this -> render('Display',array('db'=>$model));


 

        } 

    }


    


?>



The auto refresh doesn’t work… I wonder is my mistaken in assign

$(’#myDIV’).fadeOut(‘slow’).load(‘MyController.php’).fadeIn(“slow”);

please help

I’m not sure what you are trying to do, but why are you fading your controller. I don’t think you can call the controller like that.

I’m guessing your trying to bring up some data from a DB. I would suggest you make a function actionPageName inside your controller. Make the page inside your view and then call that.

If you explain a little more it will also help others. :)

Thanks

Hi thanks for your reply and sorry for my English. :(

I like to refresh my div automatically without refreshing the whole page.

The time interval is 5 seconds and when it refreshing i want to show the latest count of record and empID in database.

http://www.yiiframework.com/forum/index.php/topic/49527-update-content-with-ajax-and-ajax-auto-refresh-div/page__view__findpost__p__230887