http://www.w3.org/TR/XMLHttpRequest/ -------------------------------------------------------------------------------- In the following example an XMLDOM document containing order information is posted to an ASP page which returns the result as a new XML document. function xmlpost() { //code (client-side jscript): var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); xmlhttp.Open("POST", "http://guruserver/processorder.asp", false); xmlhttp.Send(xmldoc); return xmlhttp.responseXML; } The ASP page then loads the posted XML document, processes it, and builds an XML document from the results: <% //code (server-side jscript): Response.Expires=-1000; var doc = Server.CreateObject("Microsoft.XMLDOM"); doc.load(Request); // process and build resulting document var result=Server.CreateObject("Microsoft.XMLDOM"); Response.ContentType="text/xml"; result.save(Response); %> -------------------------------------------------------------------------------- A function to return a cross-browser XMLHTTP Object: function getXMLHttpObj(){ if(typeof(XMLHttpRequest)!='undefined') return new XMLHttpRequest(); var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i; for(i=0;i<axO.length;i++) try{ return new ActiveXObject(axO[i]); }catch(e){} return null; } Most browsers other than Internet Explorer 5 or 6 have a built-in XMLHttpRequest object. Internet Explorer 7, when it's released, will also have this object natively. The first thing we do is check to see if this object exists. If it does, we create an instance of it and that's it. If the object doesn't exist, we attempt to create one of several ActiveX Objects. We don't know what objects our users have installed, so we attempt to create several different XMLHTTP objects, starting with the newest ones. Internet Explorer 7 added native support for the XMLHttpRequest object, but retains backward compatibility with the ActiveX implementation. The version independent method for all versions of IE is Microsoft.XMLHTTP. -------------------------------------------------------------------------------- C++ Code Snip and Understand The MS XMLHTTP Object Versions #import "msxml3.dll" using namespace MSXML2 XML = new ActiveXObject('Msxml2.XMLHTTP.3.0') -------------------------------------------------------------------------------- function randomexample() { var args = arguments swtich(args[0]) { this that } var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest() if (x) { x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { el = document.getElementById(args[2]) } } } x.open("GET",args[1],true) x.send(null) } -------------------------------------------------------------------------------- function x(data) { // take care of data } function handler() { if(this.readyState == 4 && this.status == 200) { if(this.responseXML!=null && this.responseXML.getElementById('test').firstChild.data) // success! x(this.responseXML.getElementById('test').firstChild.data) else x(null) } else if (this.readyState == 4 && this.status != 200) { // fetched the wrong page or network error... x(null) } } var client = new XMLHttpRequest() client.onreadystatechange = handler client.open("GET","test.xml") client.send() -------------------------------------------------------------------------------- The following script: var client = new XMLHttpRequest() client.open("GET", "test.txt", true) client.send() client.onreadystatechange = function() { if(this.readyState == 3) print(this.getAllResponseHeaders()) } Should output something similar to the following text: Date: Sun, 24 Oct 2004 04:58:38 GMT Server: Apache/1.3.31 (Unix) Keep-Alive: timeout=15, max=99 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/plain; charset=utf-8 The following script: var client = new XMLHttpRequest() client.open("GET", "test.txt", true) client.send() client.onreadystatechange = function() { if(this.readyState == 3) print(client.getResponseHeader('content-type')) } Should output something similar to the following text: Content-Type: text/plain; charset=utf-8 For getResponseHeader(): If the state is not receiving or loaded, the user agent must raise an INVALID_STATE_ERR exception. If more than one header of the given name was received, then the values must be concatenated, separated from each other by an U+002C COMMA followed by an U+0020 SPACE. If no headers of that name were received, then it must return null. --------------------------------------------------------------------------------