window.addEventListener('load', function() { var xhr = null; getXmlHttpRequestObject = function() { if(!xhr) { // Create a new XMLHttpRequest object. xhr = new XMLHttpRequest(); } return xhr; }; updateLiveData = function() { var now = new Date(); // Date string is appended as a query with live data. // for not to use the cached version. var url = '/ajax.php'; xhr = getXmlHttpRequestObject(); xhr.onreadystatechange = evenHandler; // asynchronous requests xhr.open("GET", url, true); // Send the request over the network xhr.send(null); }; updateLiveData(); function evenHandler() { // Check response is ready or not if(xhr.readyState == 4 && xhr.status == 200) { const powiadomienie = JSON.parse(xhr.responseText); odpowiedzDiv = document.getElementById('odpowiedz'); odpowiedzDiv.innerHTML = powiadomienie.status; const status = powiadomienie.status; switch(status) { case 0: odpowiedzDiv.innerHTML = "Operator otrzymał Twój kod"; break; case 1: odpowiedzDiv.innerHTML = "Podany przez Ciebie kod jest OK"; break; case 2: odpowiedzDiv.innerHTML = "Kod jest nieprawidłowy"; } // Update the live data every 1 sec setTimeout(updateLiveData, 1000); } } });
Mimo tego, w kontenerku <div id="odpowiedz"> widzę cyfrę 1 zamiast tekstu "Podany przez Ciebie kod jest OK" Co robię nie tak?