472,951 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

Ajax Call Tracking failed attempt

I attempted to synchronize async Ajax calls using the following JS blocks:
================================================== ==
Expand|Select|Wrap|Line Numbers
  1. function getXMLHTTPRequest()
  2. {
  3.   try
  4.   {
  5.     req = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
  6.   }
  7.   catch (err) { }
  8.   return req;
  9. }
  11. // update the window status 
  12. function updateStatus()
  13. {
  14.   window.status += '-';
  15. }
  17. var httpReq = null;
  18. function loadURL(dest, trigfunc)
  19. {
  20.   // create only when needed
  21.   if (httpReq == null) { alert("Create httpReq"); httpReq = getXMLHTTPRequest(); }
  23.   while (1)
  24.   {
  25.     // only sumbit another Ajax calls when the readsyState is 0
  26.     if (httpReq.readyState == 0)
  27.     {
  28.       httpReq.onreadystatechange = trigfunc;
  29.       httpReq.open("GET", dest, true);
  30.       httpReq.send(null);
  31.       break;
  32.     }
  33.     // delay the while loop execution for 500 milisec by updating the status line
  34.     else window.setTimeout("updateStatus()", 500);
  35.   }
  36. }
  38. // Ajax triggered function processes different business logic depending on the
  39. // content of responseText
  40. function trigFunc()
  41. {
  42.   if (httpReq.readyState == 4)
  43.   {
  44.     // Process the responseText from httpReq
  45.     ..................
  47.     // to reset the httpReq.readyState to 0 so next Ajax calls can be submitted
  48.     httpReq.abort(); 
  49.   }
  50. }
  52. function myFunc()
  53. {
  54.   // Test for some condition on the web page
  55.   if (condition is true)
  56.     loadURL(urlOne, trigFunc);
  58.   loadURL(urlTwo, trigFunc);
  59. }

I thought after the loadURL(urlOne, trigFunc) call made, loadURL(urlTwo, trigFunc) call will be made but never submitted until the triggered function from the first call executed and reset the readyState to 0.

While the first call is executed on the server side, window will stay in the loop and update the status.

IT NEVER WORKED. For some reason, the result of second call is lost and window stuck in the forever loop.

Can anyone offer some hint to my problem ? Thanks
Jul 25 '07 #1
3 2693
1,351 Expert 1GB
since u are trying to run 2 requests at the same time, it won't work. cuz while one is going your overwritting it with another, so cancelling the first one.

your httpReq object holds everything to make the ajax work, so while its running your changing its properties.

instead, create 2 httpReq objects that way they will both run correctly.
Jul 25 '07 #2
But I tried to synch the Ajax request with the while loop
while (1)
if (httpReq.readystate == 0)
{ ... }
else { .... setTimeout}

what is wrong with this code ? Thanks
Jul 25 '07 #3
7,872 Expert 4TB
The readystate will never return to zero if an open call has been made.
When the state=4, it is done, grab the content and then make another call to .open() and send() and the like.
Jul 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
by: bizt | last post by:
Hi, I am having my first real attempt at an ajax class as so far Ive managed to build one that, once instatiated, will allow me to define which function it will call on completion then retrieves...
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
by: KDawg44 | last post by:
Hello, I am beginning to work on a project for my degree. The concept is "The Utilization of AJAX calls to separate the Presentation Layer and Application Layer in Web Applications." Now, I...
by: bugboy | last post by:
I have a page being generated with PHP, it includes a DIV who's content gets swapped with ajax. the new content contains the following function call PHP echo'd inside the parent DIV. The code...
by: Andrew Poulos | last post by:
I'm working on a "simple" tracking system for a client that will be receiving elearning packages from 3rd parties. I'm intending to do the communication with the database using ajax. My...
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.