Autor | Zpráva | ||
---|---|---|---|
majo20 Profil * |
#1 · Zasláno: 6. 10. 2009, 20:43:30
Potreboval by som automaticky aktualizovať (refreshnúť) iba určitú časť stránky. Zatiaľ som na internete našiel toto:
function refresh(){ $("#refresh_div").load("page_refresh.php"); setTimeout("refresh()", "1000"); } A neviem ako ďalej. Viem ešte že na stránke musí byť div s ID refresh_div, ale neviem napríklad, ako toto spustiť automaticky pri načítaní stránky. Ak môžete, napíšte ako to má presne vyzerať, prípadne kde nájdem odpovede. Ďakujem. |
||
fajzen Profil |
#2 · Zasláno: 6. 10. 2009, 21:20:38
tak si ešte nájdi pojem AJAX ;)
prípadne si preštuduj aspoň základy jQuery (v nej je písaný uvedený kód) |
||
rhuliak Profil |
#3 · Zasláno: 6. 10. 2009, 21:20:42
na hento musis mat kniznicu jQuery a tu funkciu zavolas v tagu body....
<body onload="refresh();"> |
||
fajzen Profil |
#4 · Zasláno: 6. 10. 2009, 21:23:55
rhuliak
nehovorím, že je to zle, ale jQuery bola práveže navrhnutá tak, aby sa do body nemuselo dávať žiadne onload... lepšie je to takto: <script> $().ready(refresh); </script> |
||
majo20 Profil * |
#5 · Zasláno: 6. 10. 2009, 23:05:35
Dakujem.
Už som našiel na nete funkčný jednoduchý script na obnovu stránky, ale je tam menší problém. Nefunguje v IE6. Nemáte náhodou niekto funkčný script, ktorý by fungoval na všetkých bežných prehliadačoch? tu je ten môj script: <html> <head> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ refreshDiv(); }); function refreshDiv() { $("#diwwin").load("load_page.php", function() { setTimeout("refreshDiv();", 2000); } ); } </script> </head> <body> <div id="diwwin"> </div> </body> </html> |
||
_es Profil |
#6 · Zasláno: 6. 10. 2009, 23:34:00
majo20
Síce s jQuery nerobím, no mohlo by fungovať: <html> <head> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(refreshDiv); function refreshDiv() { $("#diwwin").load("load_page.php", function() { setTimeout(refreshDiv, 2000); } ); } </script> </head> <body> <div id="diwwin"> </div> </body> </html> |
||
majo20 Profil * |
#7 · Zasláno: 7. 10. 2009, 19:20:21
_es
Nefunguje ani toto. Skúšané na IE 6.00.... |
||
Chamurappi Profil |
#8 · Zasláno: 7. 10. 2009, 20:05:00
Reaguji na maja20:
Prosím o odkaz na živou ukázku. |
||
_es Profil |
#9 · Zasláno: 7. 10. 2009, 20:11:07
majo20
Popíš detailne, čo presne sa snažíš dosiahnuť. Možno ti niekto poradí lepšie. |
||
majo20 Profil * |
#10 · Zasláno: 7. 10. 2009, 21:29:09
Dík všetkým. Už som našiel na webe funkčný script, ktorý funguje na firefoxe, opere, IE 6,...:
<script type="text/javascript"> var xmlhttp = false ; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest (); } catch (e) { xmlhttp = false} } function myXMLHttpRequest () { var xmlhttplocal; try { xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")} catch (e) { try { xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")} catch (E) { xmlhttplocal = false; } } if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') { try { var xmlhttplocal = new XMLHttpRequest (); } catch (e) { var xmlhttplocal = false; } } return (xmlhttplocal); } var mnmxmlhttp = Array (); var mnmString = Array (); var mnmPrevColor = Array (); var responsestring = Array (); var myxmlhttp = Array (); var responseString = new String; var i=0; var ii = 0; function ajax_update() { url = "load_page.php"; target2 = document.getElementById ('content'); ii = i++; var content = "i=" + ii ; mnmxmlhttp = new myXMLHttpRequest (); if (mnmxmlhttp) { mnmxmlhttp.open ("POST", url, true); mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded'); mnmxmlhttp.send (content); errormatch = new RegExp ("^ERROR:"); target2 = document.getElementById ('content'); mnmxmlhttp.onreadystatechange = function () { if (mnmxmlhttp.readyState == 4) { mnmString = mnmxmlhttp.responseText; if (mnmString.match (errormatch)) { mnmString = mnmString.substring (6, mnmString.length); target = document.getElementById ('content'); target2.innerHTML = mnmString; } else { target = document.getElementById ('content'); target2.innerHTML = mnmString; } } } } setTimeout('ajax_update()', 1000); } </script> <BODY onload="ajax_update();"> <div id="content"></div> </BODY> |
||
Časová prodleva: 15 let
|
0