Skip to content

Instantly share code, notes, and snippets.

@NachoMan
Created October 17, 2009 20:32
Show Gist options
  • Save NachoMan/212444 to your computer and use it in GitHub Desktop.
Save NachoMan/212444 to your computer and use it in GitHub Desktop.
function loadHTML(node, url, timeout) {
if (timeout == undefined)
timeout = 10000;
var req = new XMLHttpRequest();
var timer = setTimeout(function() {
try {
req.abort();
} catch(e) {}
navigator.notification.loadingStop();
}, );
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status < 300) {
clearTimeout(timer);
var html = req.responseText;
html.replace(/.*<body>/, '');
html.replace(/<\/body>.*/, '');
node.innerHTML = html;
}
navigator.notification.loadingStop();
delete req;
delete node;
}
};
req.open('GET', url, true);
req.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment