mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 16:46:26 +00:00
f7ad4265ef
nsISupportsString -> nsISupportsCString nsISupportsWString -> nsISupportsString r=dougt, sr=jag
145 lines
3.8 KiB
HTML
145 lines
3.8 KiB
HTML
<html>
|
|
<head><title>POST test</title>
|
|
<style type="text/css">
|
|
.box {
|
|
display: box;
|
|
border: 1px solid black;
|
|
margin-bottom: 0.5em;
|
|
}
|
|
.boxheader {
|
|
font-weight: bold;
|
|
color: maroon;
|
|
}
|
|
pre {
|
|
margin-left: 2em;
|
|
}
|
|
</style>
|
|
<script type="text/javascript">
|
|
var p;
|
|
try {
|
|
p = new XMLHttpRequest();
|
|
} catch (e) {
|
|
p = new ActiveXObject("Msxml2.XMLHTTP");
|
|
}
|
|
|
|
// In Mozilla, you can only create the text string if you can bybass security, like in chrome
|
|
var sendPlainTextData = false;
|
|
|
|
var docsize = 400; // the document has docsize*2+1 elements
|
|
var x;
|
|
if (!sendPlainTextData) {
|
|
try {
|
|
x = document.implementation.createDocument("", "test", null);
|
|
var i;
|
|
for (i = 0; i < docsize; i++) {
|
|
var fooElement = document.createElement("Foo");
|
|
fooElement.appendChild(document.createTextNode("My Stuff\nYeah"));
|
|
x.documentElement.appendChild(fooElement);
|
|
x.documentElement.appendChild(document.createElement("Bar"));
|
|
}
|
|
} catch (e) {
|
|
x = new ActiveXObject("Msxml2.DOMDocument");
|
|
var str = "<?xml version='1.0'?>\n<test>";
|
|
var i;
|
|
for (i = 0; i < docsize; i++) {
|
|
str += "<Foo>My Stuff\nYeah</Foo><Bar/>";
|
|
}
|
|
str += "</test>";
|
|
x.loadXML(str);
|
|
}
|
|
}
|
|
|
|
var interactiveCount = 0;
|
|
|
|
function myfunc()
|
|
{
|
|
if (p.readyState == 3) {
|
|
interactiveCount++;
|
|
}
|
|
//alert("myfunc readyState=" + p.readyState);
|
|
//if (p.readyState == 2) {
|
|
// alert(p.getAllResponseHeaders());
|
|
// alert(p.status);
|
|
//}
|
|
if (p.readyState != 4)
|
|
return;
|
|
|
|
document.getElementById("id1").firstChild.nodeValue = p.responseText;
|
|
if (p.responseXML) {
|
|
var str;
|
|
try {
|
|
var s = new XMLSerializer();
|
|
var d = p.responseXML;
|
|
str = s.serializeToString(d);
|
|
} catch (e) {
|
|
str = "@@TODO@@";
|
|
}
|
|
document.getElementById("id2").firstChild.nodeValue = str;
|
|
}
|
|
document.getElementById("id3").firstChild.nodeValue = p.getAllResponseHeaders();
|
|
document.getElementById("id4").firstChild.nodeValue = p.status;
|
|
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
|
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
|
document.getElementById("id7").firstChild.nodeValue = interactiveCount;
|
|
}
|
|
|
|
// p.onload would also work in Mozilla
|
|
p.onreadystatechange = myfunc;
|
|
|
|
try {
|
|
// Needed for Mozilla if local file tries to access an http URL
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
|
|
} catch (e) {
|
|
// ignore
|
|
}
|
|
|
|
//alert("before open():" +p.readyState);// 0 = UNINITIALIZED
|
|
p.open("POST", "http://green/cgi-bin/echo_xml.cgi");
|
|
//alert("after open():" +p.readyState);// 1 = LOADING
|
|
|
|
if (!sendPlainTextData) {
|
|
//alert("Going to send");
|
|
p.send(x);
|
|
//alert("Done to send");
|
|
} else {
|
|
var mystr;
|
|
try {
|
|
var WSTRING_CONTRACTID = "@mozilla.org/supports-string;1";
|
|
mystr = Components.classes[WSTRING_CONTRACTID].createInstance(Components.interfaces.nsISupportsString);
|
|
mystr.data = "Heikki's data";
|
|
} catch (e) {
|
|
mystr = "Heikki's data";
|
|
}
|
|
p.send(mystr);
|
|
}
|
|
//alert("after send():" +p.readyState);// 1 = LOADING
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h1>POST test</h1>
|
|
|
|
<div class="box"><span class="boxheader">responseText</span>
|
|
<pre id="id1">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader">responseXML serialized</span>
|
|
<pre id="id2">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader">getAllResponseHeaders()</span>
|
|
<pre id="id3">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader">status</span>
|
|
<pre id="id4">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader">statusText</span>
|
|
<pre id="id5">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader">readyState</span>
|
|
<pre id="id6">@@No result@@</pre>
|
|
</div>
|
|
<div class="box"><span class="boxheader"># of times onreadystatechanged handler called with INTERACTIVE status</span>
|
|
<pre id="id7">@@No result@@</pre>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|