Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP] Problem z odświeżaniem elementu
koxu1996
post
Post #1





Grupa: Zarejestrowani
Postów: 139
Pomógł: 3
Dołączył: 5.06.2011

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


Witam. Napisałem w php kod który pokazuje czas do danego wydarzenia, a javacripcie dałem interwał który to ma pobrać i wyświetlić. Część działa bo onload ładuje to co zwraca funkcja, lecz dalej już się nie odświerza.

Kod:
  1. <html>
  2. <body>
  3. <div id=time></div>
  4.  
  5.  
  6. <script type="text/javascript">
  7. window.onload = function()
  8. {
  9. idElement = "time";
  10. document.getElementById(idElement).innerHTML = "<?php countdown(21,00,00,9,15,2012) ?>" ;
  11. setInterval("document.getElementById(idElement).innerHTML = '<?php countdown(21,00,00,9,15,2012) ?>'", 1000);
  12. };
  13. </script>
  14.  
  15.  
  16.  
  17. <?php
  18. function countdown($godzina,$minuta,$sekunda,$miesiac,$dzien,$rok)
  19. {
  20. $target = mktime($godzina,$minuta,$sekunda,$miesiac,$dzien,$rok);
  21. $now = time() ;
  22. $sekundy =($target-$now) ;
  23. //$sekundy =(int) ($sekundy) ;
  24.  
  25.  
  26. $check=0;
  27. if ($sekundy>0)
  28. {
  29. if ($check==0)
  30. {
  31. if ($sekundy<=10000)
  32. {
  33. // zmien klase
  34. $check=1;
  35. }
  36. }
  37. $hours=floor($sekundy/3600);
  38. $minutes=floor(($sekundy/60)-($hours*60));
  39. $seconds=floor(($sekundy)-($hours*3600)-($minutes*60));
  40.  
  41.  
  42. if($hours < 10)
  43. $hours='0'.$hours;
  44.  
  45. if($minutes < 10)
  46. $minutes='0'.$minutes;
  47.  
  48. if ($seconds < 10)
  49. $seconds='0'.$seconds;
  50.  
  51.  
  52.  
  53.  
  54. $all= $hours . " : " . $minutes . " : " . $seconds;
  55. echo $all;
  56. }
  57. else
  58. {
  59. echo "Aukcja zakończona!";
  60. }
  61. }
  62. ?>
  63.  
  64.  
  65.  
  66. </body>
  67. </html>

Podejrzewam że coś źle połączyłem js z php, ale to tylko moje przypuszczenia ;p Czemu to może nie działać?

P.s Demo: -> KLIK <-

Ten post edytował koxu1996 16.09.2012, 12:21:02
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
koxu1996
post
Post #2





Grupa: Zarejestrowani
Postów: 139
Pomógł: 3
Dołączył: 5.06.2011

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


Próbowałem zrobić to za pomocą liczenia różnicy czasu między komputerem i serwerem, ale to nie za dobrze działało. Teraz zrobiłem plik time.php który zwraca czasy oddzielone średnikami, lecz nie wiem za bardzo jak pliku index.php pobrać to co zwraca time.php. Jak to zrobić?

Edit: Znalazłem coś takiego:

  1. var isIE = false;
  2. var requests = new Array();
  3. function getRequestObject() {
  4. if (requests.length < 1) {
  5. //log("new request " + typeof XMLHttpRequest);
  6. if (window.XMLHttpRequest && !(window.ActiveXObject)) {
  7. try {
  8. return new XMLHttpRequest();
  9. } catch (e) {log("to nie jest FF");}
  10. }
  11. isIE = true;
  12. //log("IE");
  13. // Internet Explorer
  14. try {
  15. return new ActiveXObject("Msxml2.XMLHTTP.6.0");
  16. } catch(e) {}
  17. try {
  18. return new ActiveXObject("Msxml2.XMLHTTP.3.0");
  19. } catch(e) {}
  20. try {
  21. return new ActiveXObject("Msxml2.XMLHTTP");
  22. } catch(e) {}
  23. try {
  24. return new ActiveXObject("Microsoft.XMLHTTP");
  25. } catch(e) {}
  26. //log("This browser does not support XMLHttpRequest." );
  27. return undefined;
  28. } else {
  29. //log("reuse request");
  30. return requests.pop();
  31. }
  32. }
  33. function releaseRequestObject(request) {
  34. //log("releasing request");
  35. requests.push(request);
  36. }
  37. function sendRequest(callback, url, id) {
  38. var request = getRequestObject();
  39. if (request != undefined) {
  40. var d = new Date();
  41. url = url + "t=" + d.getTime();
  42. if (isIE) {
  43. request.open("GET", url, true);
  44. if (callback != null) {
  45. if (id != null) {
  46. request.onreadystatechange = function() { callback(request, id);};
  47. } else {
  48. request.onreadystatechange = function() { callback(request);};
  49. }
  50. } else {
  51. request.onreadystatechange = function() {};
  52. }
  53. } else {
  54. if (callback != null) {
  55. if (id != null) {
  56. request.onload = function() { callback(request, id);};
  57. } else {
  58. request.onload = function() { callback(request);};
  59. }
  60. } else {
  61. request.onload = function() {};
  62. }
  63. request.open("GET", url, true);
  64. }
  65. request.send(null);
  66. //log("request sent " + typeof request + ", " + isIE);
  67. } else {
  68. //log("nic nie wysyłamy bo się nie da");
  69. }
  70. }

Jakby to wykorzystać?

Ten post edytował koxu1996 24.09.2012, 08:11:29
Go to the top of the page
+Quote Post

Posty w temacie


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: 8.10.2025 - 14:05