I'd like to perform multiple XMLHTTP requests but one after the other,
ie. do next when previous one comes back ok.
Identifier to determine when to start the next one is a global
variable whose value is reset to none ("") with XMLHTTP handler
function. For example:
var someGlobal = "";
for(var i=0; i<10; i++){
if(someGlobal ==""){
someGlobal = i+"";
//do XMLHTTP request where handler function makes someGlobal = ""
at the end
}
}
Obviously, this will not work (or will work once) because someGlobal
will NOT be empty for the second loop since request takes some time to
finish and reset someGlobal.
Please advise as to how to implement it best. Thanks. 8 2423
*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM:
[snip]
>
Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
All the best,
~A!
--
anthony at my pet programmer dot com
On Jan 9, 3:49 pm, Anthony Levensalor <killf...@mypet programmer.com>
wrote:
*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM:
[snip]
Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
All the best,
~A!
--
anthony at my pet programmer dot com
Thanks, but I prefer figuring this out rather than using 3-party file.
*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 4:23 PM:
On Jan 9, 3:49 pm, Anthony Levensalor <killf...@mypet programmer.com>
wrote:
>*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM: [snip]
>>Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
All the best, ~A!
-- anthony at my pet programmer dot com
Thanks, but I prefer figuring this out rather than using 3-party file.
Sure thing. I'd use an array to queue the XHRs, and since you usually
can only have two going at a time, I'd wait until one completed, then
kick off the next, etc, etc.
Good luck, let me know how it works out for you, I'm interested in
seeing your solution when you get one, just for discussion and
edification. :)
~A!
--
anthony at my pet programmer dot com
On Wed, 09 Jan 2008 13:23:09 -0800, vunet wrote:
On Jan 9, 3:49 pm, Anthony Levensalor <killf...@mypet programmer.com>
wrote:
>*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM: [snip]
Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
All the best, ~A!
-- anthony at my pet programmer dot com
Thanks, but I prefer figuring this out rather than using 3-party file.
Another option would be to go ahead and kick them all off. If my
understanding is correct, they should queue when started. Increment a
counter when it starts, decrement it when one finishes. When the counter
hits zero jump to your next bit of code.
When I needed multiple bits of data returned, I ended up choosing a
server-side method that dropped one big chunk at me that I could then
split up.
if (http.status == 200) {
var json = eval( "(" + http.responseTe xt + ")" );
plist = json["plist"];
mlist = json["map"];
plist2 = json["ody"];
}
yeah, yeah yea.. eval ... I know. Its my server and my data and I'm
the only one with write access to the DB.
"vunet" <vu******@gmail .comwrote in message
news:b5******** *************** ***********@d70 g2000hsb.google groups.com...
I'd like to perform multiple XMLHTTP requests but one after the other,
ie. do next when previous one comes back ok.
Identifier to determine when to start the next one is a global
variable whose value is reset to none ("") with XMLHTTP handler
function. For example:
var someGlobal = "";
for(var i=0; i<10; i++){
if(someGlobal ==""){
someGlobal = i+"";
//do XMLHTTP request where handler function makes someGlobal = ""
at the end
}
}
Obviously, this will not work (or will work once) because someGlobal
will NOT be empty for the second loop since request takes some time to
finish and reset someGlobal.
Please advise as to how to implement it best. Thanks.
One kludge I used was launch timer before the request checking status of
global var that is updated when status==200.
The timer calls itself for a determined number of callbacks before crapping
out, otherwise when the global var says Ok, then send the next request..
vunet said the following on 1/9/2008 4:23 PM:
On Jan 9, 3:49 pm, Anthony Levensalor <killf...@mypet programmer.com>
wrote:
>*** vunet *** wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM: [snip]
>>Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
All the best, ~A!
-- anthony at my pet programmer dot com
Thanks, but I prefer figuring this out rather than using 3-party file.
View Matt's source and figure out how he did it.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
vunet wrote:
I'd like to perform multiple XMLHTTP requests but one after the other,
ie. do next when previous one comes back ok. [...]
Please advise as to how to implement it best. Thanks.
// only for demo
var i = 0;
function makeRequest()
{
var me = arguments.calle e;
// add alternatives, feature tests and exception handling here
var req = new XMLHttpRequest( );
req.open("GET", "/?" + i++, true);
req.onreadystat echange = function()
{
if (req.readyState == 4 && /^(0|2\d\d)$/.test(req.statu s))
{
window.setTimeo ut(me, 1000);
}
};
req.send(null);
}
makeRequest();
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
On Jan 9, 3:49*pm, Anthony Levensalor <killf...@mypet programmer.com>
wrote:
*** vunet **** *wrote a whole bunch of nifty stuff On 1/9/2008 3:43 PM:
[snip]
Please advise as to how to implement it best. Thanks.
http://ajaxtoolbox.com
Already been done for you, by some of the best coders in the business.
It was done by one coder and I would hesitate to call him one of the
best in the business.
IIRC, that code does not do exactly what the OP requested (it makes
requests in parallel, rather than sequentially.) Depending on the
OP's needs, that may be the best solution.
Peter Michaux has posted some proposed code for this in a CWR ticket
that looks to be more robust than this example. Unfortunately, the
Trac server has been down lately. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AIMTech |
last post by:
We have an IIS+ASP based application server that is capable of providing
complex reports to hundreds of users but in some circumstances these reports
can take a long time to create. However the data for the report is cached
so subsequent calls to view the same report come back with a sub-second
response time.
In order to make use of this...
|
by: jim.frantzen |
last post by:
You have an active XMLHTTP request on the main page
(localhost/App1/index.aspx) The XMLHTTP request takes about 60 seconds
to receive a response back from localhost/App1/getxml.aspx.
You have an IFRAME on this main page.
When you set the iframe's src to google.com, it works fine.
When you set the iframe's src to localhost/App1/test.htm,...
|
by: daninbrum |
last post by:
Dear All,
Please excuse the following thickness, I am new to client scripting.
I have set up a page comprising of three DIVs, the content of which
gets changed by XMLHTTP requests (including the following code in a
function).
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
document.getElementById(loc).innerHTML =...
|
by: peterlan |
last post by:
Hello,
I have an issue with a long-running import process in our asp.net app (1.1).
After the user initiates an import, we're trying to make periodic xmlhttp
requests to update a progress bar. In development (running the webserver on
localhost) this works fine. When we move the code to our build environment,
the webserver won't respond to the...
|
by: mike.biang |
last post by:
I have an ASP page that is using an XMLHTTP object to request various
pages from my server. I keep a single session throughout the XMLHTTP
requests by bassing the ASPSESSIONID cookie through the XMLHTTP object.
However, when the page requested through the XML object makes a
<%Response.Redirect()%>
call, a new session is created each...
| |
by: FMDeveloper |
last post by:
Currently transitioning from a shared host to a dedicated server. The
same code that works on the old server is not working on the dedicated
server. It is a simple AJAX request like:
<code>
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
|
by: Arjen |
last post by:
Hi,
I want to reload 2 divs at one click. Ive tried:
<a href = "javascript:void(0);"
onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a>
While both seperate actions work they dont when I put them together.
Anyone know how to fix this ?
My ajax.js with funcition...
|
by: Brent |
last post by:
I'm trying to figure out how to iterate over an array that would send
a series of XMLHttp requests. I'd like to have each request finish
before the next one begins, but I believe that this is not possible to
do in a straightforward fashion, given the normally asynchronous
method of XMLHttp. The (untested, pseudo) code below gives a little...
|
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 the contents
from a server side script as AJAX generally does and process it using
that function. This far Im quite pleased with it, however, I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |