IIS ASP - Multiple XMLHTTPREQUESTS and Queuing...

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > April 2006 > Multiple XMLHTTPREQUESTS and Queuing...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Multiple XMLHTTPREQUESTS and Queuing...
blueapricot416@gmail.com

2006-04-27, 7:51 am

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/DEM...ultiple_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

blueapricot416@gmail.com

2006-04-27, 7:51 am

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[i].xmlhttp.readyState == 4)
{
if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status ==
304)
{
// 200 OK
update_log(xmlreqs[i].xmlhttp.responseText,-1)
xmlreqs.splice(i,1); i--;
}
else
{
// error
xmlreqs.splice(i,1); i--;
alert("A problem occurred!");
}
}
}
}

Anthony Jones

2006-04-27, 7:51 am

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.

<blueapricot416@gmail.com> wrote in message
news:1145154622.004145.152110@u72g2000cwu.googlegroups.com...
> 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[i].xmlhttp.readyState == 4)
> {
> if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status ==
> 304)
> {
> // 200 OK
> update_log(xmlreqs[i].xmlhttp.responseText,-1)
> xmlreqs.splice(i,1); i--;
> }
> else
> {
> // error
> xmlreqs.splice(i,1); i--;
> alert("A problem occurred!");
> }
> }
> }
> }
>



blueapricot416@gmail.com

2006-04-27, 7:51 am

>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

Anthony Jones

2006-04-27, 7:51 am


<blueapricot416@gmail.com> wrote in message
news:1145204363.282115.263670@i39g2000cwa.googlegroups.com...
>
> 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.


blueapricot416@gmail.com

2006-04-27, 7:51 am

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

Anthony Jones

2006-04-27, 7:51 am


<blueapricot416@gmail.com> wrote in message
news:1145212635.239202.308620@i39g2000cwa.googlegroups.com...
> 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).


>
> Thanks so much,
> Blue Apricot
>




blueapricot416@gmail.com

2006-04-27, 7:51 am

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

I really appreciate it.

Blue Apricot

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com