I am developing a small web application. I have pretty much finished the server side code, but am struggling with the client side javascript.
I have an html file that is updated every second. This file is fully static and I use it only for log purposes.
The idea is to do pretty much the same thing, but with an auto update done on the client side.
For that I want to use database polling using ajax.
I have implemented a first version here, that simply prints the same html file and is supposed to reload it every second.
The thing is that is doesn't update, even though I don't see any error in my javascript console client side. The file is found, as it loads correctly and I don't see any reason why it wouldn't update my div.
Here is my code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Using Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
(function worker() {
$.ajax({
url : 'http://jlengrand.pythonanywhere.com/static/leader.html',
success: function(data) {
$('.text').html(data);
},
complete: function() {
setTimeout(worker, 1000);
}
});
})();
</script>
</head>
<body>
<div class="text">
To be loaded <br />
</div>
</body>
</html>
I tried locally (but with a smaller file) and it worked fine.
I know that reloading the whole file is not clever, but I want to build incrementally as this is the first time I develop in JavaScript.
What am I missing?