R
RossGK
I'm a bit new to javascript - as will be obvious below.
I'm using an XMLHttpRequest to get a bit of data from server (django),
and it works nicely for single events. But my eventual outcome needs
to be a series of data transmissions. I figured requesting data over
and over until the data is some value that triggers the stop would be
an interesting first attempt. To move forward, I wrapped my initial
single data request in a for-loop to see if I could do multiple calls.
Here's my javascript stuff...
for (i=0;i<=5;i++) {
xmlHttp.onreadystatechange=function()
{ if (xmlHttp.readyState==4)
{ document.myForm.myvar.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","/ajax_data",true);
xmlHttp.send(null);
//alert("got here")
dopause(500); //wait 500ms
}
What I've noticed is that with that alert line commented out, nothing
seems to happen -ie I don't see the data receive. I expected to see
it flash 5 times (the server sends a random number)
When I put the alert in, the alert does in fact pop up, and the data
gets displayed.
Does the alert message cause a window refresh that I need to emulate
when the alert is not there. What do I need to do to make it cycle
through the get 5 times and actually show me what comes up, WITHOUT
using an alert pop!?
Thanks for any suggestions
I'm using an XMLHttpRequest to get a bit of data from server (django),
and it works nicely for single events. But my eventual outcome needs
to be a series of data transmissions. I figured requesting data over
and over until the data is some value that triggers the stop would be
an interesting first attempt. To move forward, I wrapped my initial
single data request in a for-loop to see if I could do multiple calls.
Here's my javascript stuff...
for (i=0;i<=5;i++) {
xmlHttp.onreadystatechange=function()
{ if (xmlHttp.readyState==4)
{ document.myForm.myvar.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","/ajax_data",true);
xmlHttp.send(null);
//alert("got here")
dopause(500); //wait 500ms
}
What I've noticed is that with that alert line commented out, nothing
seems to happen -ie I don't see the data receive. I expected to see
it flash 5 times (the server sends a random number)
When I put the alert in, the alert does in fact pop up, and the data
gets displayed.
Does the alert message cause a window refresh that I need to emulate
when the alert is not there. What do I need to do to make it cycle
through the get 5 times and actually show me what comes up, WITHOUT
using an alert pop!?
Thanks for any suggestions