Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Co robię nie tak?
DNMX
post
Post #1





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

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


Mam taki kod:
  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 = '/ajax.php';
  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. updateLiveData();
  30.  
  31. function evenHandler()
  32. {
  33. // Check response is ready or not
  34. if(xhr.readyState == 4 && xhr.status == 200)
  35. {
  36. const powiadomienie = JSON.parse(xhr.responseText);
  37. odpowiedzDiv = document.getElementById('odpowiedz');
  38. odpowiedzDiv.innerHTML = powiadomienie.status;
  39. const status = powiadomienie.status;
  40. switch(status) {
  41. case 0:
  42. odpowiedzDiv.innerHTML = "Operator otrzymał Twój kod";
  43. break;
  44. case 1:
  45. odpowiedzDiv.innerHTML = "Podany przez Ciebie kod jest OK";
  46. break;
  47. case 2:
  48. odpowiedzDiv.innerHTML = "Kod jest nieprawidłowy";
  49. }
  50. // Update the live data every 1 sec
  51. setTimeout(updateLiveData, 1000);
  52. }
  53. }
  54. });

Mimo tego, w kontenerku <div id="odpowiedz"> widzę cyfrę 1 zamiast tekstu "Podany przez Ciebie kod jest OK" Co robię nie tak?
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: 3.10.2025 - 23:06