CodeIgniter Forums
Auto refresh particular div using jquery or AJAX - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Auto refresh particular div using jquery or AJAX (/thread-53507.html)



Auto refresh particular div using jquery or AJAX - El Forum - 07-26-2012

[eluser]Unknown[/eluser]
Hi everyone,

i'm a beginner in using the codeigniter and i have a question on how to refresh particular div using jquery or ajax. i've tried to search and try to fix it but it is not working.

this is my view page:
home_page.php
Code:
function test(){
            $('#jobs').html("<?php $this->load->view('jobs_page.php'); ?>");
            
        }
        setInterval( "test()", 1000 );

this is the div that needs to be auto updated
Code:
<div id="jobs" class="middle_row">
        &lt;? $this->load->view('jobs_page.php'); ?&gt;
</div>

this is the jobs_page.php
Code:
<table border="1" width="100%" bgcolor="transparent">
                    <tr>
                        <td width="10px">No.</td>
                        <td>Description</td>
                        <td>Status</td>
                        <td>Progress</td>
                        <td width="70px">Project %</td>
                        <td>Deadline</td>
                        <td>Action</td>
                    </tr>
                    &lt;?
                        $result = $jobs;
                        foreach($result as $row)
                        {    
                    ?&gt;
                    <tr>
                        <td>&lt;? echo $row->id; ?&gt;</td>
                        <td>&lt;? echo $row->prj_name; ?&gt;</td>
                        <td>&lt;? echo $row->status; ?&gt;</td>
                        <td>&lt;? echo $row->progress; ?&gt;</td>
                        <td>&lt;? echo $row->prj_percent; ?&gt;</td>
                        <td>&lt;? echo $row->deadline; ?&gt;</td>
                        <td>&lt;input type="text" id="tester"&gt;&lt;/td>
                    </tr>
                    &lt;?  } ?&gt;
</table>

any help regarding this is highly appreciated. Thank you before.


Auto refresh particular div using jquery or AJAX - El Forum - 07-27-2012

[eluser]CroNiX[/eluser]
Javascript runs in the clients browser. It doesn't know php.

Use ajax to periodically send a request to the server via POST. In the controller/method that the ajax request is calling, return the desired view. Then, in the success event of the ajax call, show the returned HTML in your div.