Here is the code for the simple AJAX functions I am using.
I will extend it some more later on, IE handle both GET and POST, as well as basic auth.
I know there are other more graceful libraries out there, but for now, my needs are simple.
Thanks to the number of different web authors, who I stole/borrowed bits and pieces of code from.
var http_request = false;
function makeRequest(url,divid) {
div_id = divid;
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up
Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
document.getElementById(div_id).innerHTML = http_request.responseText;
} else {
alert('There was a problem with the request.');
}
}
}
function removeContents(divid) {
document.getElementById(divid).innerHTML = "";
}
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks