473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Ajax loop question

Hi,

Can anyone find why this setTimeout() loop isn't working - I'm getting:

'data_to_send' is undefined

Any help much appreciated, thanks.

BTW, ajax.js contains my handling for creating the XMLHttpRequest, called createRequest().

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script src="ajax.js" type="text/javascript"></script>
  5.  
  6. <script language="JavaScript">
  7.  
  8. function getData(data_to_send,zone_id)
  9.     var url = "realtime_read_values.php";
  10.     var req = create_request(); 
  11.     req.open("POST", url, true); 
  12.     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  13.     req.send(data_to_send); 
  14.     req.onreadystatechange = function()
  15.     {
  16.         if(req.readyState == 4 && req.status == 200)
  17.         {
  18.             document.getElementById(zone_id).innerHTML  = req.responseText;
  19.             //setTimeout("getData(window.data_to_send)", 3000); // this doesn't work
  20.         } 
  21.     }
  22.     setTimeout("getData(data_to_send,zone_id)", 5000);
  23.  
  24. </script>
  25.  
  26. <body onload="getData('graph_request=graph_counter1','zone1'); getData('graph_request=graph_counter2','zone2'); getData('graph_request=graph_counter3','zone3');">
  27.  
  28. <div id="zone1">
  29. waiting for data..
  30. </div>     
  31.  
  32. <div id="zone2">
  33. waiting for data..
  34. </div>     
  35.  
  36. <div id="zone3">
  37. waiting for data..
  38. </div>     
  39.  
  40. </body>
  41. </html>
  42.  
Sep 14 '08 #1
1 1192
Ferris
101 100+
Hi
I think , as a string type of setTimeout's 1st parameter, your parameters (data_to_send,zone_id) will not pass to the function getData.

Expand|Select|Wrap|Line Numbers
  1. setTimeout("getData(data_to_send,zone_id)", 5000);
you can use anonymous function to do it.
try this:

Expand|Select|Wrap|Line Numbers
  1. setTimeout(function(){ getData(data_to_send,zone_id); }, 5000);
Regards.
Sep 15 '08 #2

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

Similar topics

5
by: darrel | last post by:
I've been playing with prototype.js and scriptaculous to create some nice drag-and-drop interaction on my applications GUI. That's working well. Now I want to take the next step and start passing...
2
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...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
by: nghivo | last post by:
I attempted to synchronize async Ajax calls using the following JS blocks: ==================================================== function getXMLHTTPRequest() { try { req =...
7
by: MikeB | last post by:
Hello All, I am new to ajax and wanted to start by trying something simple. I have a web form with an updatepanel and then inside the update panel I have a listbox. Then outside of the updatepanel...
6
by: sheldonlg | last post by:
I came across a problem and googling for an answer didn't help. What I want to do is run an AJAX script that sets a hidden variable on the form. I call the AJAX script from a javascript...
20
by: Bryan A | last post by:
Is there a way to add a timeout to this script so that it times out at a certain time. So it would be auto updating every 2seconds and it would timeout like after 100 seconds with a message?. ...
2
by: Chris | last post by:
I'm developing an ASP.NET Page that processes some files, does some things to them. I'd like to have a gridview that displays each file, and it's status, if it's done processing, still processing,...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.