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 on “Using XMLHTTPRequest in Mozilla”

Leave a Comment

Close
  • E-mail
  • Social Web

Email this page to a friend:

E-mail It

Buy Music

Download Scott Andrew tracks from iTunes Find Scott Andrew at Rhapsody Find Scott Andrew at Amazon Find Scott 
Andrew at CD Baby

New Videos

More Videos

Photos

More Photos at Flickr

Recent Reader Comments

  • Dave: $1 for the bonus tracks? BOOM! I'm there.
  • Shelby: you're a phenomenal artist. definitely going on th...
  • Steve Rydz: Great song Scott, good to hear something new. Kee...
  • Volker: Really good song! I am curious about the bonus ver...
  • scottandrew: Thanks for the comments, everyone. Hopefully I'll ...