I'm looking for a script that will automatically update a page but not reload it. I have one example, these divs are automatic reloading: http://prntscr.com/603k2n
It's not my page of course, here is link: http://suna.e-sim.org/battle.html?id=13317 (you will need to register).
I tried with jQuery but it won't reload PHP, just HTML. I need to reload MySQL and PHP - is it even possible? i see this guys are made it.
To refresh a page without reloading, you have to load the contents of the page through ajax. You could do this as follows:
<html>
<head>
<script type="text/javascript">
$(document).on('ready', function(){
setInterval(function() {
$.ajax({
type: "GET",
url: "ajax_refresh.php",
success: function(result) {
$('body').html($result);
}
});
}, 3000);
});
</script>
</head>
<body>
<div class="header">
Header of website here
</div>
<div class="content">
Content here
</div>
<div class="footer">
Footer here
</div>
</body>
</html>
<div class="header">
Header of website here
</div>
<div class="content">
Content here
</div>
<div class="footer">
Footer here
</div>
In the above example the 'url' parameter should be a PHP file that only returns the body of the page you want to refresh. For this example to work, you should include jQuery.
Good luck
To explain this a little more. You will need a second file that looks exactly te same as your index file. Except that in this second file you do not have html, head or body tags. The content of the second file will be loaded into the first file without refreshing. This is the concept of AJAX.
For further reading: - Introduction to AJAX - W3Schools
You actually can solve this with jQuery. I recommend using setInterval. An example of how you might use it:
$(document).on('ready', function(){
setInterval(function() {
// Code that will update your page
}, 3000);
});
Remember that 3000 is the number of milliseconds before the refresh happens. So this will be called every three seconds