xmlhttp.open "GET" during browser post?

  • Thread starter Jason Morehouse
  • Start date
J

Jason Morehouse

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
 
M

Martin Honnen

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.responseText));
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.
 
J

Jason Morehouse

Martin said:
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.responseText));
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top