Benutzer:Wizard23/monobook.js: Unterschied zwischen den Versionen
aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen(9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
− | // taken from | + | // based on a simple ajax example taken from: |
// http://www.sitepoint.com/article/remote-scripting-ajax | // http://www.sitepoint.com/article/remote-scripting-ajax | ||
Zeile 5: | Zeile 5: | ||
var requester = null; | var requester = null; | ||
var formRequester = null; | var formRequester = null; | ||
+ | var metaStateTag = null; | ||
window.onload = init; | window.onload = init; | ||
Zeile 12: | Zeile 13: | ||
function init() | function init() | ||
{ | { | ||
− | + | metaStateTag = document.getElementById("metalab_state_23"); | |
− | + | if (metaStateTag != null) { | |
− | + | requestLabText(); | |
− | + | } | |
− | |||
− | |||
− | |||
return true; | return true; | ||
} | } | ||
− | |||
− | |||
Zeile 44: | Zeile 40: | ||
{ | { | ||
requester = null; | requester = null; | ||
− | |||
return false; | return false; | ||
} | } | ||
} | } | ||
− | + | try { | |
− | + | requester.onreadystatechange = onreadystatechange_requestLabText | |
− | + | requester.open("GET", "/metasense/status.txt"); | |
− | + | requester.send(null); | |
− | + | } | |
+ | catch (error) | ||
+ | { | ||
+ | } | ||
return true; | return true; | ||
} | } | ||
− | |||
− | |||
Zeile 63: | Zeile 59: | ||
function onreadystatechange_requestLabText() | function onreadystatechange_requestLabText() | ||
{ | { | ||
− | |||
// If XMLHR object has finished retrieving the data | // If XMLHR object has finished retrieving the data | ||
if (requester.readyState == 4) | if (requester.readyState == 4) | ||
Zeile 77: | Zeile 72: | ||
else if (requester.status != 0) | else if (requester.status != 0) | ||
{ | { | ||
− | alert("There was an error while retrieving the URL: " + requester.statusText); | + | //alert("There was an error while retrieving the URL: " + requester.statusText); |
} | } | ||
} | } | ||
Zeile 87: | Zeile 82: | ||
return true; | return true; | ||
} | } | ||
− | |||
/* Update users details after data is retrieved via XMLHR */ | /* Update users details after data is retrieved via XMLHR */ | ||
− | function writeDetails() | + | function writeDetails() { |
− | + | metaStateTag.innerHTML = requester.responseText; | |
− | { | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
return true; | return true; | ||
− | |||
} | } |
Aktuelle Version vom 9. Juli 2006, 18:44 Uhr
// based on a simple ajax example taken from: // http://www.sitepoint.com/article/remote-scripting-ajax var requester = null; var formRequester = null; var metaStateTag = null; window.onload = init; /* Initialisation for JS capable browsers */ function init() { metaStateTag = document.getElementById("metalab_state_23"); if (metaStateTag != null) { requestLabText(); } return true; } function requestLabText() { if (requester != null && requester.readyState != 0 && requester.readyState != 4) { requester.abort(); } try { requester = new XMLHttpRequest(); } catch (error) { try { requester = new ActiveXObject("Microsoft.XMLHTTP"); } catch (error) { requester = null; return false; } } try { requester.onreadystatechange = onreadystatechange_requestLabText requester.open("GET", "/metasense/status.txt"); requester.send(null); } catch (error) { } return true; } /* Execute the action which has been associated with the completion of this object */ function onreadystatechange_requestLabText() { // If XMLHR object has finished retrieving the data if (requester.readyState == 4) { // If the data was retrieved successfully try { if (requester.status == 200) { writeDetails(); } // IE returns a status code of 0 on some occasions, so ignore this case else if (requester.status != 0) { //alert("There was an error while retrieving the URL: " + requester.statusText); } } catch (error) { } } return true; } /* Update users details after data is retrieved via XMLHR */ function writeDetails() { metaStateTag.innerHTML = requester.responseText; return true; }