Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX][PHP] mam problem z ifem który wysyła na stronę żeby się odświeżała
szczypikrul
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 5.04.2018

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


mam problem ponieważ pobieram zmienną z bazy za pomocą ajaxa (to działa) i chcę odświeżyć if który tą zmienną porównuje jeżeli true to ma wysłać użytkownika na inną podstronę i to nie działa if znajduje się w divie echo chcę uzyskać odświeżanie tego diva np co 10s

  1. <?php
  2.  
  3. session_start();
  4.  
  5. $log = '';
  6. if(isset($_SESSION['log'])){
  7. $log = $_SESSION['log'];
  8. }
  9. if(!$log == True)
  10. {
  11. header("location: ../zaloguj.php");
  12. }
  13.  
  14. ?>
  15.  
  16. <!DOCTYPE HTML>
  17. <html lang="pl">
  18. <?php include_once('include/head.php')?>
  19. </head>
  20. <body onload="onload()" onload="onload2()">
  21. <?php include_once('include/nawigacja.php')?>
  22. <h1>GRA</h1>
  23.  
  24. <div id="echo">
  25. if($_SESSION['ile']>3)
  26. {
  27. echo "no i co";
  28. header("location: index.php");
  29. }
  30. </div>
  31.  
  32.  
  33. <h1 id="liczba" style="height: 50px;">0</h1>
  34.  
  35.  
  36. <script type="text/javascript">
  37.  
  38. function loadDoc() {
  39. var xhttp = new XMLHttpRequest();
  40. xhttp.onreadystatechange = function() {
  41. if (this.readyState == 4 && this.status == 200) {
  42. document.getElementById("liczba").innerHTML = this.responseText;
  43. }
  44. };
  45. xhttp.open("GET", "ajax/gra.php", true);
  46. xhttp.send();
  47. }
  48. function loadDoc2() {
  49. var xhttp = new XMLHttpRequest();
  50. xhttp.onreadystatechange = function() {
  51. if (this.readyState == 4 && this.status == 200) {
  52. document.getElementById("echo");
  53. }
  54. };
  55. xhttp.open("GET", "gra.php", true);
  56. xhttp.send();
  57. }
  58.  
  59. function onload()
  60. {
  61. var timeinterval = setInterval(loadDoc, 100);
  62. }
  63. function onload2()
  64. {
  65. var timeinterval = setInterval(loadDoc2, 100);
  66. }
  67.  
  68.  
  69.  
  70.  
  71. <?php include_once('include/stopka.php')?>
  72. </body>
  73.  
  74. </html>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 22.08.2025 - 05:48