I wish to load some additional data from javascript in an HTML page. The solution below is small and does exactly what I need to do in non-Microsoft browsers.
Question is, what is the Microsoft explorer equivalent?
Note that the data I’m loading isn’t in XML. I also do not wish to add a javascript library – I want this page to load fast even on dialup.
var client = new XMLHttpRequest();
client.open('GET', 'gamedata.txt');
client.onreadystatechange = function() {
if (client.readyState == 4) {
alert(client.responseText); // Make sure its loaded
}
}
client.send("");
Due to mixed support for XMLHttpRequest() in various versions of IE, you have to jump through a number of hoops to get the request to work. (In particular, IE5 and IE6 use an ActiveXObject for XMLHttpRequest.)
I’ve always used this page’s fix for IE browsers: