«
»
22.05.03

XMLHttpRequest just blew my mind

Geekism


<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 Feedbacks zu "XMLHttpRequest just blew my mind"

Nicolas Minutillo

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.



steve

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.



andyed

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



foom

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



Comments

Pleae leave a comment!




Please not: Comments may be moderated. It may take a while for them to show on the page.






Word of the Day
Your are browsing
the Archives of Steve Minutillo :: messy-78 in the 'Chinese Word of the Day' Category.
Categories
  • Chinese Word of the Day (1318)
  • Class (9)
  • Geekism (242)
  • Kung Fu (5)
  • Meta (56)
  • Mobile (32)
  • Otherwhere (62)
  • Regular (298)
  • Video Games (47)