Date: May 22nd, 2003
Cate: Geekism
Tags:

XMLHttpRequest just blew my mind

<script>
  var myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", "http://minutillo.com/some/document/", false);
  myXMLHTTPRequest.send(null);
  alert(myXMLHTTPRequest.responseText);
</script>

I had NO IDEA that you could do that. And it works in IE 5+ (with a few more lines of code to create the XMLHttpRequest object) and Netscape 6+. You can only request documents from the originating server, but that’s good enough. You could use this to make XML-RPC or SOAP (or RESTful) API calls, right from the browser, and be able to do something meaningful with the response. Whoa. Why was I not informed that this exists earlier?

Mozilla.org’s documentation.
More XML docs from Mozilla.org.
Microsoft’s documentation.

And Jim Ley puts it all together to show how it can be done cross-browser.

4 Comments

    I knew about that for the Microsoft browsers. I had no idea that Mozilla supported such a thing. Is this a standard or is it just Mozilla doing it because IE does it. Does any other browser do it (like, say, one based on KHTML)?

    Since this was always available server side–what uses do you see browser side that are cool.

    1F

  1. stevesteve  
    May 22nd, 2003
    REPLY))

  2. This seems to say that Safari doesn\’t support it, at least v60 didn\’t.

    This is good because you can make browser based apps that behave more like real apps. You can click on a button, and it will send a request off to the server and wait for and then process a response, without changing pages. It adds another way to interact with a server, above and beyond just loading pages.

    For instance if I have a webmail program, I can make the \’delete\’ button just send a (XML-RPC, SOAP, RESTful) request to the server to delete the message, and then get back an \’OK, deleted\’ message. The browser can then remove that item from the list of messages (using DOM). This will be faster and nicer than reloading the entire page.

    2F

  3. May 23rd, 2003
    REPLY))

  4. I used this tech too create an opml renderer almost a year ago :) Link in the url field.

    3F

  5. foomfoom  
    February 4th, 2004
    REPLY))

  6. Safari (as of 1.2) appears to support the XMLHttpRequest like mozilla.

    4F

Leave a Reply

 Name

 Mail

 Home

[Name and Mail is required. Mail won't be published.]