Koen Hollander
Koen Hollander

Reputation: 1701

AJAX reload every 10 seconds

i have al little code and i need to reload a block of the code every 10 seconds. Is that possible?

Code:

<?php
session_start();
$site_host = "hollander-ict.nl";
$sql_port = 3306;
$web_port = 80;

if (!fsockopen($site_host,$sql_port)) {
echo "SQLi machine error: Unreachable SQL server. Try again!";
}
if (!fsockopen($site_host,$web_port)) {
echo "SQLi machine error: Unreachable web server. Try again!";
}
?>

Upvotes: 1

Views: 4434

Answers (2)

Benz
Benz

Reputation: 2335

If you want to do this with Ajax, you can use the answer of Ben Fortune.

When you just want the page to be refreshed every 10 seconds, you can also use header()

header( 'refresh: 10; url=url-to-refresh.php' ); 

Upvotes: 1

Ben Fortune
Ben Fortune

Reputation: 32137

Something very basic to get you started. You might want to add a timeout in your code.

setInterval(function(){
    $.get('file.php', function(data){
        $('#div').html(data);
    });
},10000);

Upvotes: 2

Related Questions