HTTP Connections

Core.Web.HttpConnection provides a cross-browser wrapper around the XMLHttpRequest object that is the cornerstone of "AJAX" application development.

This wrapper provides the following benefits:

  • It provides a single API for all browsers. On all browsers except Internet Explorer 6, the HttpConnection object wraps a XMLHttpRequest object. In the case of IE6, the Microsoft.XMLHTTP ActiveX object is used
  • It provides a workaround for Safari/WebKit ampersand escaping issues which can otherwise result in invalid XML being POSTed to a server.
  • It provides event handling using traditional add/remove listener methods, rather than only the DOM Level 0 style onreadystatechange provided by XMLHttpRequest implementations.

Example

The following example shows an HttpConnection object in use:

var conn = new Core.Web.HttpConnection("/process", "POST", 
        "<msg>Hello, world<msg>", "text/xml");
conn.addResponseListener(Core.method(this, function(e) {
    if (!e.valid) {
        alert("Error!");
        return;
    }
    alert(e.source.getResponseText());
}));
conn.connect();