nsIXMLHttpRequest

  • Revision slug: nsIXMLHttpRequest
  • Revision title: nsIXMLHttpRequest
  • Revision id: 59567
  • Created:
  • Creator: Cancerbero sgx
  • Is current revision? No
  • Comment

Revision Content

page created by Sebastián (Cancerbero) Gurin sgurin@(nospam)montevideo.com.uy

Summary

Mozilla's XMLHttpRequest is modelled after Microsoft's IXMLHttpRequest object. The goal has been to make Mozilla's version match Microsoft's version as closely as possible, but there are bound to be some differences.

In general, Microsoft's documentation for IXMLHttpRequest can be used. Mozilla's interface definitions provide some additional documentation. The web page to look at is http://www.mozilla.org/xmlextras/.

Mozilla's XMLHttpRequest object can be created in JavaScript like this:

  new XMLHttpRequest()

compare to Internet Explorer:

  new ActiveXObject("Msxml2.XMLHTTP")

From JavaScript, the methods and properties visible in the XMLHttpRequest object are a combination of nsIXMLHttpRequest and nsIJSXMLHttpRequest; there is no need to differentiate between those interfaces.

From native code, the way to set up onload and onerror handlers is a bit different. Here is a comment from Johnny Stenback <jst@netscape.com>:

The mozilla implementation of nsIXMLHttpRequest implements the interface nsIDOMEventTarget and that's how you're supported to add event listeners. Try something like this: nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(myxmlhttpreq)); target->AddEventListener(NS_LITERAL_STRING("load"), mylistener, PR_FALSE) where mylistener is your event listener object that implements the interface nsIDOMEventListener. The 'onload', 'onerror', and 'onreadystatechange' attributes moved to nsIJSXMLHttpRequest, but if you're coding in C++ you should avoid using those.

Though actually, if you use addEventListener from C++ weird things will happen too, since the result will depend on what JS happens to be on the stack when you do it....

Conclusion: Do not use event listeners on XMLHttpRequest from C++, unless you're aware of all the security implications. And then think twice about it.


Interface Code

 [scriptable, uuid(7b3b3c62-9d53-4abc-bc89-c33ce78f439f)]
 interface nsIXMLHttpRequest : nsISupports
 {
   //attribtues
   readonly attribute nsIChannel channel;
   readonly attribute nsIDOMDocument responseXML;
   readonly attribute AString responseText;
   readonly attribute unsigned long status;
   readonly attribute AUTF8String statusText;
   readonly attribute long readyState;
   attribute boolean multipart;
   //methods
   void   abort();
   string getAllResponseHeaders();
   ACString getResponseHeader(in AUTF8String header);
   [noscript] void   openRequest(in AUTF8String method,
                                 in AUTF8String url,
                                 in boolean async,
                                 in AString user,
                                 in AString password);
   void   open(in AUTF8String method, in AUTF8String url);
   void   send(in nsIVariant body);
   void   overrideMimeType(in AUTF8String mimetype);
 };
 [scriptable, uuid(261676b4-d508-43bf-b099-74635a0ee2e9)]
 interface nsIJSXMLHttpRequest : nsISupports 
 {
   attribute nsIDOMEventListener onload;
   attribute nsIDOMEventListener onerror;
   attribute nsIDOMEventListener onprogress;
   attribute nsIDOMEventListener onuploadprogress;
   attribute nsIDOMEventListener onreadystatechange;
 };


Attributes

Methods

Revision Source

<p><span class="comment">page created by Sebastián (Cancerbero) Gurin sgurin@(nospam)montevideo.com.uy</span>
</p>
<h3 name="Summary">Summary</h3>
<p>Mozilla's XMLHttpRequest is modelled after Microsoft's IXMLHttpRequest object. The goal has been to make Mozilla's version match Microsoft's version as closely as possible, but there are bound to be some differences.
</p><p>In general, Microsoft's documentation for IXMLHttpRequest can be used. Mozilla's interface definitions provide some additional documentation. The web page to look at is http://www.mozilla.org/xmlextras/.
</p><p>Mozilla's XMLHttpRequest object can be created in JavaScript like this:
</p>
<pre class="eval">  new XMLHttpRequest()
</pre>
<p>compare to Internet Explorer:
</p>
<pre class="eval">  new ActiveXObject("Msxml2.XMLHTTP")
</pre>
<p>From JavaScript, the methods and properties visible in the XMLHttpRequest object are a combination of nsIXMLHttpRequest and nsIJSXMLHttpRequest; there is no need to differentiate between those interfaces.
</p><p>From native code, the way to set up onload and onerror handlers is a bit different. Here is a comment from Johnny Stenback &lt;jst@netscape.com&gt;:
</p>
<blockquote>The mozilla implementation of nsIXMLHttpRequest implements the interface  nsIDOMEventTarget and that's how you're supported to add event listeners. Try something like this:

   nsCOMPtr&lt;nsIDOMEventTarget&gt; target(do_QueryInterface(myxmlhttpreq));
   target-&gt;AddEventListener(NS_LITERAL_STRING("load"), mylistener, PR_FALSE)

where mylistener is your event listener object that implements the interface nsIDOMEventListener.

The 'onload', 'onerror', and 'onreadystatechange' attributes moved to nsIJSXMLHttpRequest, but if you're coding in C++ you should avoid using those.</blockquote>
<p>Though actually, if you use addEventListener from C++ weird things will happen too, since the result will depend on what JS happens to be on the stack when you do it....
</p><p>Conclusion: Do not use event listeners on XMLHttpRequest from C++, unless you're aware of all the security implications. And then think twice about it.
</p><p><br>
</p>
<h3 name="Interface_Code">Interface Code</h3>
<pre class="eval"> [scriptable, uuid(7b3b3c62-9d53-4abc-bc89-c33ce78f439f)]
 interface nsIXMLHttpRequest : nsISupports
 {
   //attribtues
   readonly attribute nsIChannel channel;
   readonly attribute nsIDOMDocument responseXML;
   readonly attribute AString responseText;
   readonly attribute unsigned long status;
   readonly attribute AUTF8String statusText;
   readonly attribute long readyState;
   attribute boolean multipart;
   //methods
   void   abort();
   string getAllResponseHeaders();
   ACString getResponseHeader(in AUTF8String header);
   [noscript] void   openRequest(in AUTF8String method,
                                 in AUTF8String url,
                                 in boolean async,
                                 in AString user,
                                 in AString password);
   void   open(in AUTF8String method, in AUTF8String url);
   void   send(in nsIVariant body);
   void   overrideMimeType(in AUTF8String mimetype);
 };
</pre>
<pre class="eval"> [scriptable, uuid(261676b4-d508-43bf-b099-74635a0ee2e9)]
 interface nsIJSXMLHttpRequest : nsISupports 
 {
   attribute nsIDOMEventListener onload;
   attribute nsIDOMEventListener onerror;
   attribute nsIDOMEventListener onprogress;
   attribute nsIDOMEventListener onuploadprogress;
   attribute nsIDOMEventListener onreadystatechange;
 };
</pre>
<p><br>
</p>
<h3 name="Attributes">Attributes</h3>
<h3 name="Methods">Methods</h3>
Revert to this revision