Scott Andrew - lo-fi acoustic pop superhero!

Join the Demo Club to unlock new music, get discounts, tour dates and other neato stuff:

or learn more here.

April 16, 2002

Using XMLHTTPRequest in Mozilla

Mozilla’s XMLHttpRequest object is in many ways identical to Microsoft’s XMLHTTP ActiveX object. Both can be used to make GET and POST requests from the browser. Here’s a handy tip: in Mozilla, don’t forget to use the little-known overrideMimeType() method if the server is returning anything other than text/xml. Otherwise, Mozilla might lock up on you.


try {
  // for Mozilla
  req = new XMLHttpRequest();
  req.overrideMimeType("text/xml");
} catch (e) {
  // for IE5+
  req = new ActiveXObject("Msxml2.XMLHTTP");
}
req.open("GET", "page.html",false);
req.send(null);

With overrideMimeType() Mozilla can fetch standard HTML pages, or just about anything the server would normally not return as text/xml. IE5+ doesn’t seem to have a problem with non-XML formats; probably due to its not-a-bug-it’s-a-feature behavior of ignoring mimetypes. The standard security restrictions still apply; you cannot do GET or POST requests to locations outside the current domain.

No Comments

Leave a Comment

Get The Tunes

Download Scott Andrew tracks from iTunes Find Scott Andrew at Spotify Find Scott Andrew at Emusic Find Scott Andrew at Lala Find Scott Andrew at Rhapsody Find Scott Andrew at Amazon Find Scott 
Andrew at CD Baby Find Scott Andrew at Napster

More Options

Reader Comments

New Videos

More Videos

Photos

More Photos at Flickr