473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting xmlhttprequest to loop continuously

Hi all

How can i modify my code so that js will continously check the data on
a page (data.php) and bring it through. at the moment it only does it
once when the function is called, how can i modify my code to allow for
continous looping?

function getdata() {

get = new XMLHttpRequest( );
get.onreadystat echange = processdata;
get.open("GET", "data.php") ;
get.send(null);

}

function processdata() {

if (get.readyState == 4) {
data = get.responseTex t;
document.getEle mentById("displ ay").value = data;
}

}

Dec 18 '06 #1
4 6913
I don't know php, but how about a while loop? you might need a sleep
call as well.

while (1=1)
{
execute code....
}

while (true)
{
execute code....
}

Dec 18 '06 #2
Hi,

pl************* **@yahoo.com wrote:
I don't know php, but how about a while loop? you might need a sleep
call as well.

while (1=1)
{
execute code....
}

while (true)
{
execute code....
}
First, the code is JavaScript, not PHP. The OP has a PHP page that he is
calling using a XmlHttpRequest object. The call is made in JavaScript.

Second, a while with a web request? Bad idea. Your code will (attempt
to) send tons of HTTP requests. I say attempt to, because obviously that
will fail. Best way to do what the OP wants is to send a request, wait
calmly for the response, handle the response, and then send a new
request (after possibly a little wait).

Third, you cannot sleep in JavaScript. You can schedule an action using
setTimeout if needed.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 18 '06 #3
How about setInterval() ?
I'm using it, in a Azureus Webplugin, works fine!

Dec 18 '06 #4
Hi,

tu**********@gm ail.com wrote:
How about setInterval() ?
I'm using it, in a Azureus Webplugin, works fine!
setInterval in the context of a web request is not recommended, because
you have no idea how long the web request is actually going to take. If
the server is overloaded, traffic is slow, the request takes time to be
executed, etc... then the Response will be delayed. There is a risk that
you'll send a new request before the old one is completed.

This is why I recommend a sequential approach: Send the request, wait
for the response, then use setTimeout to avoid overloading the server
with requests too close from another.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1193
by: horndude77 | last post by:
Ok, I've been reading around a lot and haven't found an answer for this. I'm using XMLHttpRequest to get an XML document from a java servlet. When the response is processed I can view the text of the XML document, but when I try and getElementsByTagName() it is null. In fact it seems that even firstChild is null. I'm just learning so go easy...
25
11257
by: Matt Kruse | last post by:
According to HTTP/1.1 specs, a client should only have two connections open to the host at a time (which can be changed by browser users, of course). When using xmlHttpRequest connections, is there any way to detect that the request is queued? I did some tests (see "Queued Requests" at http://www.ajaxtoolbox.com/request/examples.php ) and...
1
9473
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHomeForm')" after clicking on button i am getting following error:- object...
4
2704
by: libsfan01 | last post by:
Hi all I want to have create a js function to use xmlhttprequest continously check a given url for any change in its value and then bring the contents of that page through. Here is my code so far, it just pulls is through once when the function is called, i would like it to work continuously: function getdata() {
2
3824
by: dmagliola | last post by:
Hello all, I'm experiencing a problem with ASP.Net for which I can't find a reasonable explanation, or any information. I'm currently developing an application that, through AJAX, asks the server for updated information to show, and can also send information to the server. To do this, I have an XMLHttpRequest that queries an...
4
2977
by: jeff.maildump | last post by:
Hi, I've got multiple xmlhttprequests which are in a loop. So this is the loop I have so far, with the closure given to me in a previous post: //------------------------------------------------------------------------------------- for (i=0; i<data.length; i++) { httpRequest = false; httpRequest = new XMLHttpRequest();...
6
5080
by: raknin | last post by:
Hi, I have html page that part of it is static and part of it changing continuously. What I want to do is, in the static part of the page I want to run an hidden ajax script in a loop that run in the background and checks continuously the DB for some information, while the active part of the page is changing continuously by the user. If the...
19
4352
by: RossGK | last post by:
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...
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7472
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...
0
7743
Oralloy
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. ...
0
7986
jinu1996
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...
1
5391
isladogs
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...
0
5114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1965
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
0
786
bsmnconsultancy
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...

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.