469,270 Members | 1,737 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

xmlhttp.open "GET" during browser post?

Hello,

Anyone know if it's possible to speak with the server via xmlhttp.open
while the browser is doing a post -- file upload in this case:

<form enctype="multipart/form-data" action="product" method="post"
name="product" onSubmit="do_action_form(); return true;">
....
<script>
// .. setup xmlhttp here.
function do_action_form() {
xmlhttp.open("GET", '/upload?file_id=173729929292')
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
xmlhttp.send(null);
}
</script>

This code works fine if not being using during a (browser) post, but
dies with:

Error: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
upload/file_id=42442662626 :: anonymous :: line 356" data: no]

The purpose of this is to check the file upload status (eta / size etc)
with the server as a file is being uploaded.

Thanks,
-J
Jul 23 '05 #1
2 2665


Jason Morehouse wrote:

Anyone know if it's possible to speak with the server via xmlhttp.open
while the browser is doing a post -- file upload in this case:

<form enctype="multipart/form-data" action="product" method="post"
name="product" onSubmit="do_action_form(); return true;">
...
<script>
// .. setup xmlhttp here.
function do_action_form() {
xmlhttp.open("GET", '/upload?file_id=173729929292')
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
An alert dialog is modal and blocks the browser so it is detrimental to
use it if you want to have one request done while another is being
performed in another thread.

This code works fine if not being using during a (browser) post, but
dies with:

Error: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
upload/file_id=42442662626 :: anonymous :: line 356" data: no]


Could you check whether the error goes away if you do not use alert?
If you want to output the responseText you could try
var p;
if (document.createElement && (p = document.createElement('p'))) {
p.appendChild(document.createTextNode(xmlhttp.resp onseText));
document.body.appendChild(p);
}
but I have no idea whether the browser is able to change the document
while a file upload has already been started.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin Honnen wrote:
Could you check whether the error goes away if you do not use alert?
If you want to output the responseText you could try
var p;
if (document.createElement && (p = document.createElement('p'))) {
p.appendChild(document.createTextNode(xmlhttp.resp onseText));
document.body.appendChild(p);
}
but I have no idea whether the browser is able to change the document
while a file upload has already been started.


Thanks. Yeids the same results. I guess it doesn't like it when a file
is being uploaded... atleast not in Firefox anyway. Haven't tried IE.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom S | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.