dobry den
potreboval by som script ktory by mi refreshol stranku ale tak aby to nebolo vidno v prehliadaci pomocou php a ajaxu.
dufam ze som to napisal dost zrozumitelne
dakujem za pomoc
Fórum › PHP
Auto reload stranky

To 7raul : jak chceš reloadnout stránku aby to nebylo vidět v prohlížeči????
jestli chceš automaticky provést kód na stránce, aniž by ten skript někdo spustil použij cron(); jinak si to neumím vysvětlit, kdyžtak to blíž popiš
tak nikto nevie ako nato????
To 7raul : ...v JavaScripte urob cyklus napr. každých 5 min. a každých 5 min bude volať window.location.reload();
var i = getMinutes();
if(i++){
document.window.location.reload();
}
Refresh každú minútu...
To 7raul : ja by som ti mohol pomoct, da sa tam dokonca nastavit aj cas v sekundach za kolko sa to refreshne
<script language="JavaScript">
var countDownInterval=10; /tu je ten interval refreshu v sekundach
var c_reloadwidth=200
</script>
<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Ďaľší <a href="javascript:window.location.reload()">refresh</a> za<b id="countDownText">'+countDownTime+' </b> sekúnd')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}
function startit(){
if (document.all||document.getElementById)
document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> sekúnd')
countDown()
}
if (document.all||document.getElementById)
startit()
else
window.onload=startit
</script>
Když si mluvil o AJAXu tak zkus tohle
nejdřív si do stránky šoupneš třeba takovyto div
<div id="online" style="float: left; width: 180px;">Právě probýhá aktualizace dat. Prosím počkejte</div>
pak budes potrebovat nalinkovat tenhle JS soubor
window.setInterval("online()", 1000);
function online() {
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (eror) {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
}
http_request.onreadystatechange = function() { take_data(http_request); };
http_request.open('POST', './inc/ajax_background.php', true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(null);
}
function take_data(http_request) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var area = document.getElementById('online');
area.innerHTML = http_request.responseText;
} else {
var area = document.getElementById('online');
area.innerHTML = 'Omlouváme se, ale došlo k chybě na straně severu. Tato služba je dočasně nedostupná.';
}
}
}
a do tretice takovej backend pojmenovl jsem ho ajax_background.php (viz: http_request.open('POST', './inc/ajax_background.php', true); ) nebudu to upravat dam tam co jsem si zkousel
include_once("./inc/db.php");
db_open(false);
$sql_online = my_query("SELECT user FROM online WHERE 1=1 ORDER BY user");
while($online = my_fetch_array($sql_online)){
echo $online["user"]."";
}
$count_online = my_num_rows($sql_online);
if($count_online == 1) { $user_word = "Je připojen: $count_online uživatel"; }
if($count_online >= 2 AND $count_online <= 4) { $user_word = "Jsou připojení: $count_online uživatelé"; }
if($count_online >= 5) { $user_word = "Je připojeno $count_online uživatelů"; }
if($count_online != 0) {
echo "<hr />$user_word";
} else {
echo "<hr />Není připojen žádný uživatel";
}
jop mala poznamka v ty "knihovne" db.php mam trosku poupraveny mysql funkce tak sem si nadefinoval svoje my_query() atd,.. tak bacha kdyz to jen zkopirujes tak ti to bude hazet chyby :-)
no a pokud tam nemam zadnou chybu tak by to mělo každou vterinu refreshovat obsah toho divu a uzivatel to pozna jen tehdy kdyz se zmeni vysledek, ktery generuje ajax_background.php, což v mém případě je když se někdo prihlasil nebo odhlasil.

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 47 hostů
Podobná vlákna
Reload stránky — založil yxcvb
Reload stránky a složka — založil roman.jaros
Oříšek: reload stránky s běžícím scriptem — založil Petroff
Auto spustenie jQuery po načítaní stránky — založil Majovic
VB - Reload picture — založil Denoy
Moderátoři diskuze