Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Odświeżanie strony
DNMX
post
Post #1





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 18.09.2021

Ostrzeżenie: (0%)
-----


Jak odświeżyć po stronie użytkownika zawartośc strony ale nie za pomocą tagu <meta> ani skryptu window.reload() tylko tak, żeby mu się u góry w przeglądarce kółeczko nie kręciło??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
viking
post
Post #2





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Napisać do producentów przeglądarek żeby dodali taką funkcjonalność (IMG:style_emoticons/default/smile.gif)
Możesz przeładować stronę dynamicznie np przez fetch().
Go to the top of the page
+Quote Post
DNMX
post
Post #3





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 18.09.2021

Ostrzeżenie: (0%)
-----


A jak to robi np. FB, że u góry zawsze widać facebook.com a przechodzi się na różne strony?
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




np. AJAX
Go to the top of the page
+Quote Post
gino
post
Post #5





Grupa: Zarejestrowani
Postów: 324
Pomógł: 52
Dołączył: 18.02.2008

Ostrzeżenie: (0%)
-----


zerknij np. tutaj:
Update data on a page without refreshing
Go to the top of the page
+Quote Post
DNMX
post
Post #6





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 18.09.2021

Ostrzeżenie: (0%)
-----


Dzięki gino. Zrobiłem zgodnie z Twoim tutorialem ale updatuje w kółko w pętli bez czekania.
  1. window.addEventListener('load', function()
  2. {
  3. var xhr = null;
  4.  
  5. getXmlHttpRequestObject = function()
  6. {
  7. if(!xhr)
  8. {
  9. // Create a new XMLHttpRequest object
  10. xhr = new XMLHttpRequest();
  11. }
  12. return xhr;
  13. };
  14.  
  15. updateLiveData = function()
  16. {
  17. var now = new Date();
  18. // Date string is appended as a query with live data
  19. // for not to use the cached version
  20. var url = 'livefeed.txt?' + now.getTime();
  21. xhr = getXmlHttpRequestObject();
  22. xhr.onreadystatechange = evenHandler;
  23. // asynchronous requests
  24. xhr.open("GET", url, true);
  25. // Send the request over the network
  26. xhr.send(null);
  27.  
  28. };
  29.  
  30. updateLiveData();
  31.  
  32. function evenHandler()
  33. {
  34. // Check response is ready or not
  35. if(xhr.readyState == 4 && xhr.status == 200)
  36. {
  37. dataDiv = document.getElementById('liveData');
  38. // Set current data text
  39. dataDiv.innerHTML = xhr.responseText;
  40. // Update the live data every 1 sec
  41. setTimeout(updateLiveData(), 1000);
  42. }
  43. }
  44. });

Zmiana setTimeout(updateLiveData(), 10000); nie pomaga
Go to the top of the page
+Quote Post
nospor
post
Post #7





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie
setTimeout(updateLiveData(), 1000);

a:
setTimeout(updateLiveData, 1000);
Go to the top of the page
+Quote Post
DNMX
post
Post #8





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 18.09.2021

Ostrzeżenie: (0%)
-----


Działa elegancko, również na mobilnych
Go to the top of the page
+Quote Post
viking
post
Post #9





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


I pomyśleć że zamiast 3 linijek nowoczesnego fetch API łatwiej było użyć 40 przestarzałego XMLHttpRequest
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 20:38