Skip to content

Instantly share code, notes, and snippets.

Created June 28, 2010 13:47
Show Gist options
  • Save anonymous/455857 to your computer and use it in GitHub Desktop.
Save anonymous/455857 to your computer and use it in GitHub Desktop.
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null;
}
return xhr;
}
function loadContents(page, id){
xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById(id).innerHTML = '';
document.getElementById(id).innerHTML = xhr.responseText;
}
};
xhr.open("GET", page, true);
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment