User:Hippietrail/hippajax.js
Note – after saving, you may have to bypass your browser’s cache to see the changes.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
// abstract function to do xmlhttprequest
function ajax(url, on200, on404) {
var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
req.open('GET', url, true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
// TODO handle xmlhttprequest cache bug in some msie versions
if (req.responseText == '') {
on404();
} else {
on200(req);
}
} else if (req.status == 404) {
on404();
} else {
debugPrint('bad rsc status ' + req.status + '\n');
}
}
};
req.send(null);
}