Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLHttpRequest - Open ("POST",url,true) not working like I thought

Status
Not open for further replies.

DaveSefton

Programmer
Feb 25, 2010
9
US
Hello

I'm trying to start a process and then continue on with my current page while this process is running in background. My assumption with code below is that once POST is sent, it will then continue thru code and 'submit' the form 'without' waiting for POST process to complete. The 'submit' works fine but it always waits for process to complete before submitting form.

Thx for any help, Dave

.....code below...........

<script type="text/javascript">
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
//alert("new");
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
//alert("old");
}
//
sAJOrdnum = "99900150";
sAJLine = "2";
url = " + sAJOrdnum + "&LINENUM=" + sAJLine;
//alert (url);
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
document.forms[0].action = ' + 'Test';
document.forms[0].submit();
}
</script>
 
This might seem like a stupid question, but how do you know that the AJAX appears to be behaving synchronously?

What happens, for example, if you put an alert in right after this line?:

Code:
xmlhttp.send(null);

Does it appear immediately? If so, the problem is not what you think it is.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 

Dan

Yes, I have put that alert in the code and it appears quickly ,but, the form that is suppose to be 'submitted' afterwards does not display until the AJAX process is complete. I have code in the AJAX process that keeps this process running for 1-2 minutes ,which is about the same amount of time before my form is displayed. I've also tested with longer 'times' with same results.
This form does not do any processing other than display another page ,so, it should be spontaneous.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top