Welcome Guest, Not a member yet? Register   Sign In
How to reload the div using ajax
#2

[eluser]eoinmcg[/eluser]
firstly, refactor your code and embrace MVC.

i'd move the building of the file list to a model.
in your controller you'll then get the files from the model and send it to a view.

Code:
//in your controller
$dir = 'path/to/dir';
$data['files'] = $this->model_name->build_file_list($dir);
$this->load->view('viewname.php', $data);


//in your view: viewname.php
<div id="ajax_wrap">
<div id="ajax_using">
&lt;?php foreach ($files as $file): ?&gt;
<a href="&lt;?php echo ">&lt;?php echo $file; ?&gt;</a>
&lt;?php endforeach; ?&gt;
</div>
</div>

now that things are not such a mess, a splash of jquery would be the easiest way to update
Code:
update();

function update() {
  $.ajax({
    type: 'POST',
    url: '/controller/method',
    timeout: 2000,
    success: function(data) {
        $("#ajax_wrap").html(data);

      window.setTimeout(update, 20000);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        // deal with possible errors
      window.setTimeout(update, 20000);
    }
    });
}


Messages In This Thread
How to reload the div using ajax - by El Forum - 05-10-2011, 01:21 AM
How to reload the div using ajax - by El Forum - 05-10-2011, 02:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB