Multiple XMLHTTPREQUESTS and Queuing...

B

blueapricot416

Hello helpful computer people!

I can't seem to get more than one request to fire simultaneously... and
I have read there should be at least 2 possible (in IE) and more in
Firefox.

I made a demo based on this article/code "Handling Multiple
XMLHTTPRequest Objects" at
http://www.drakware.com/articles/multijax.php, which does make mutliple
requests, but never two seem to happen at the same time.

See my demo at:

http://s161149005.onlinehome.us/DEMOS/AJAX/1/multiple_03a.htm

Hit a bunch of buttons and see how they start "sending", but always
"answer back" in order. If there were 2 calls happening
simultaneously, the shorter calls (Button C, which does only "5
Calculations/Loops") would "jump" over the longer calls when it
answered back.

1. Am I missing something? (Or am I right, there is only one request
happening at a time)
2. Can I do anything to get more than one XMLHTTPRequest going at a
time?
3. Could this be a server issue? (Maybe ASP/IIS has a limit on the
backend?)

Thanks for any help. I just started doing the Ajax stuff, and thought
I saw a world of opportunity, but if I can't get more than one thread
at a time I don't know how much use it will be to me...

Thanks for any comments/help,
Blue Apricot
 
B

blueapricot416

If it helps, here is some code. There are 3 files, a normal HTML page
that has the buttons, an external Javascript file (see below), and a
simple ASP file that does some dummy calculations to "waste time" and
then sends a Response.Write back to the page that started things...

Here is the .js:

function update_log(t,num)
{
document.getElementById('put_here').innerHTML =
document.getElementById('put_here').innerHTML +
' <br>' + t + ' [# of connections: ' + parseInt(xmlreqs.length+num)
+']'
}

function sendData(l,x)
{
update_log('<b><i>Button "' + l + '" clicked, Sending
Request</i></b>',1)
var queryString = 'AJXloops=' + x + '&AJXaction=' + l
var url="respond_main_03a.asp";
xmlreqPOST(url,queryString)
}

//
------------------------------------------------------------------------------------------------
// Based on Code from http://www.drakware.com/articles/multijax.php
//
------------------------------------------------------------------------------------------------

var xmlreqs = new Array();

function CXMLReq(type, xmlhttp)
{
this.type = type;
this.xmlhttp = xmlhttp;
}

function xmlreqGET(url)
{
var xmlhttp=false;
if (window.XMLHttpRequest)
{
// Mozilla, etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
// IE
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
if(! xmlhttp)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
var xmlreq = new CXMLReq('', xmlhttp);
xmlreqs.push(xmlreq);
}



function xmlreqPOST(url,data)
{
var xmlhttp=false;
if (window.XMLHttpRequest)
{
// Mozilla etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=xmlhttpChange;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send(data);
}
else if (window.ActiveXObject)
{
// IE
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
xmlhttp.onreadystatechange=xmlhttpChange;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send(data);
}
}

var xmlreq = new CXMLReq('', xmlhttp);
xmlreqs.push(xmlreq);
}


function xmlhttpChange()
{
if (typeof(window['xmlreqs']) == "undefined") return;

for (var i=0; i < xmlreqs.length; i++)
{
if (xmlreqs.xmlhttp.readyState == 4)
{
if (xmlreqs.xmlhttp.status == 200 || xmlreqs.xmlhttp.status ==
304)
{
// 200 OK
update_log(xmlreqs.xmlhttp.responseText,-1)
xmlreqs.splice(i,1); i--;
}
else
{
// error
xmlreqs.splice(i,1); i--;
alert("A problem occurred!");
}
}
}
}
 
A

Anthony Jones

Do you jhave debugging enabled on your ASP application? If so it will only
process one request at a time. So your second request remains in the request
queue at server until the first request is finished.

Anthony.

If it helps, here is some code. There are 3 files, a normal HTML page
that has the buttons, an external Javascript file (see below), and a
simple ASP file that does some dummy calculations to "waste time" and
then sends a Response.Write back to the page that started things...

Here is the .js:

function update_log(t,num)
{
document.getElementById('put_here').innerHTML =
document.getElementById('put_here').innerHTML +
' <br>' + t + ' [# of connections: ' + parseInt(xmlreqs.length+num)
+']'
}

function sendData(l,x)
{
update_log('<b><i>Button "' + l + '" clicked, Sending
Request</i></b>',1)
var queryString = 'AJXloops=' + x + '&AJXaction=' + l
var url="respond_main_03a.asp";
xmlreqPOST(url,queryString)
}

//
-------------------------------------------------------------------------- ----------------------
// Based on Code from http://www.drakware.com/articles/multijax.php
//
-------------------------------------------------------------------------- ----------------------

var xmlreqs = new Array();

function CXMLReq(type, xmlhttp)
{
this.type = type;
this.xmlhttp = xmlhttp;
}

function xmlreqGET(url)
{
var xmlhttp=false;
if (window.XMLHttpRequest)
{
// Mozilla, etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
// IE
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
if(! xmlhttp)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
var xmlreq = new CXMLReq('', xmlhttp);
xmlreqs.push(xmlreq);
}



function xmlreqPOST(url,data)
{
var xmlhttp=false;
if (window.XMLHttpRequest)
{
// Mozilla etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=xmlhttpChange;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send(data);
}
else if (window.ActiveXObject)
{
// IE
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
xmlhttp.onreadystatechange=xmlhttpChange;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send(data);
}
}

var xmlreq = new CXMLReq('', xmlhttp);
xmlreqs.push(xmlreq);
}


function xmlhttpChange()
{
if (typeof(window['xmlreqs']) == "undefined") return;

for (var i=0; i < xmlreqs.length; i++)
{
if (xmlreqs.xmlhttp.readyState == 4)
{
if (xmlreqs.xmlhttp.status == 200 || xmlreqs.xmlhttp.status ==
304)
{
// 200 OK
update_log(xmlreqs.xmlhttp.responseText,-1)
xmlreqs.splice(i,1); i--;
}
else
{
// error
xmlreqs.splice(i,1); i--;
alert("A problem occurred!");
}
}
}
}
 
B

blueapricot416

Do you jhave debugging enabled on your ASP application?

Hmmm, how can I find out?

I didn't change any settings or put in code that I think would enable
debugging, but I am not sure how to do it, so could it have been done
by default? Or on a standard IIS install?

Blue Apricot
 
A

Anthony Jones

Hmmm, how can I find out?

I didn't change any settings or put in code that I think would enable
debugging, but I am not sure how to do it, so could it have been done
by default? Or on a standard IIS install?

Blue Apricot

No you'd have to turn it on deliberately.

Open properties of the application folder or web site, select home directory
tab and open the application configuration dialog. On the App Debugging
page if any of the debugging flags are checked then debugging is enabled for
the application.

When debugging is enabled there is only a single worker thread to process
requests. Hence multiple requests will get queued.

But of course I'm being really dumb ("nothing new there!" I hear a few
snigger)...

Requests to ASP pages by the same session will have to be serialised. The
Session state object is a Single Threaded object it can't be shared by two
requests being processed simultaneously. You might try the App Options tab
of the Application Configuration dialog and turn off 'Enable session state'
that will probably help I've not tried it myself. Of course if you need
session state then you're stuck but I think this will help prove your AJAX
stuff.

Anthony.
 
B

blueapricot416

Thanks Anthony,
I turned off 'Enable session state' and my Ajax stuff is working now.
Thanks for walking me through that.

One final quick question (sorry)...

What will be the impact of turning off session state?

Can I still use session variables, for instance?
Will it effect stuff in my Global.asa file?

Thanks so much,
Blue Apricot
 
A

Anthony Jones

Thanks Anthony,
I turned off 'Enable session state' and my Ajax stuff is working now.
Thanks for walking me through that.

One final quick question (sorry)...

What will be the impact of turning off session state?

Can I still use session variables, for instance?

Nope session variables will not be available
Will it effect stuff in my Global.asa file?

Application events and the application object should continue as normal.

I've not tried it but I suspect the session events won't run at all
(otherwise they'd have to run for every request and that would be
undesirable).
 
B

blueapricot416

Thank you very much for your answers, Anthony. You have been a great
help.

I really appreciate it. :)

Blue Apricot
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top