MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Nerdberg
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 4: Zeile 4:
xhr.onload = function() {
xhr.onload = function() {
     if (xhr.status === 200) {
     if (xhr.status === 200) {
        alert('User\'s name is ' + xhr.responseText);
    json = JSON.parse(xhr.responseText);
    }
   
    else {
var para = document.createElement("p");
        alert('Request failed. Returned status of ' + xhr.status);
var node = document.createTextNode(json.results[1].status);
para.appendChild(node);
 
var parent = document.getElementById("doorstatus");
var child = document.getElementById("p1");
parent.replaceChild(para, child);
     }
     }
};
};
xhr.send();
xhr.send();

Version vom 6. Oktober 2019, 19:41 Uhr

/* Das folgende JavaScript wird für alle Benutzer geladen. */
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://doorstatus.nerdberg.de/api/doorstatus/');
xhr.onload = function() {
    if (xhr.status === 200) {
    	json = JSON.parse(xhr.responseText);
    	
		var para = document.createElement("p");
		var node = document.createTextNode(json.results[1].status);
		para.appendChild(node);

		var parent = document.getElementById("doorstatus");
		var child = document.getElementById("p1");
		parent.replaceChild(para, child);
    }
};
xhr.send();