gecko-dev/extensions/xmlextras/tests/post.html

45 lines
1.0 KiB
HTML
Raw Normal View History

<html>
<body>
<h1>Posting test</h1>
<script>
const WSTRING_CONTRACTID = "@mozilla.org/supports-wstring;1";
var sendPlainTextData = false; // you can only create the text string if you can bybass security
var x;
if (!sendPlainTextData) {
x = document.implementation.createDocument("", "test", null);
x.documentElement.appendChild(document.createTextNode("Foo"));
}
var p = new XMLHttpRequest();
function myfunc()
{
var s = new XMLSerializer();
var str;
if (!sendPlainTextData) {
var d = p.responseXML;
str = s.serializeToString(d);
} else {
str = p.responseText;
}
alert(str);
alert(p.getAllResponseHeaders());
}
p.onload = myfunc;
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
p.open("POST", "http://green/cgi-bin/echo_xml.cgi");
if (!sendPlainTextData) {
p.send(x);
} else {
var mystr = Components.classes[WSTRING_CONTRACTID].createInstance(Components.interfaces.nsISupportsWString);
mystr.data = "Heikki's data";
p.send(mystr);
}
</script>
</body>
</html>