The problem is that I don't know how to set the number of seconds after which timeout is declared (and $html is empty). Maybe I wasn't lucky enough while searching into Simple HTML DOM documentation.
Such code will be included in a PHP page, and an eventual timeout on an <? include ?> will heavily affect the main page.
So I decided to discard <? include ?> and choose an AJAX function instead.
If you consider that:
- the main page already needs jquery, so I'm not actually adding kylobytes to the page
- the code parsed from $html will ALREADY needs Javascript, so users without JS aren't really affected by jquery
- such output doesn't need to be indexed by search engines
- in case of timeout (and only when the cachefile has expired) the main page won't be affected, and a nice "Loading..." text will appear in that div
- today I realized that the output should be refreshed every 100 seconds
I thought that it could have been a good idea to use this function (we've gone OT in this way, but in case somebody has the same problem I thought that it was worth to post my solution):
(function($)
{
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#foo_content').hide();
$('#foo_loading').show();
},
complete: function() {
$('#foo_loading').hide();
$('#foo_content').show();
},
success: function() {
$('#foo_loading').hide();
$('#foo_content').show();
}
});
var $container = $("#foo_content");
$container.load('foo.php');
var refreshId = setInterval(function()
{
$container.load('foo.php');
}, 100000); //refresh every 100 seconds
});
})(jQuery);