nsIXMLHttpRequest

이 기사는 기술적인 검토가 필요합니다.

아직 자원봉사자들이 한국어로 이 기사를 번역하지 않았습니다. 가입해서 이 문서가 번역되는 일에 함께 해 주세요!

nsIXMLHttpRequest along with nsIJSXMLHttpRequest and nsIXMLHttpRequestEventTarget are Mozilla's implementation details of the DOM XMLHttpRequest object.

Note: If you're a web developer or a Mozilla add-on developer, please refer to the XMLHttpRequest documentation instead.

This page contains documentation, specific to Mozilla application and add-on developers.

The interface definition: http://mxr.mozilla.org/mozilla-centr...ttpRequest.idl

Using event handlers from native code

(Not sure if it's up-to-date)

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.

Example code

This is a simple example code for opening a simple HTTP request from a xul application (like a Mozilla extension) without using observers:

 var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
 req.open('POST', "http://www.foo.bar:8080/nietzsche.do", true);
 req.send('your=data&and=more&stuff=here');

Document Tags and Contributors

Last updated by: kscarfone,