简体   繁体   中英

Timing confusion in AJAX

I have a code to plot a real time graph using a javascript library "FLOT". I am getting the data from mysql every 500mS using AJAX technology. I have the main() function that is calling handleresponse() function which retreives data from database and in the handleresponse() function again I have given setTimeout(main(),500). So, every 500mS the things are getting repeated and dynamically the graph is getting plotted. But the time axis is not moving according to the data.. the data is getting updated only at a particular point. the appearance of the data and time axis is not synchronised.

It would be a pleasure to debug your problem if there would be some code.

Anyway here is a suggestion:

You create a timeout to update the graph. And you have a timer for the AJAX call?

Try to combine these (you only need one timer). Just use the timer for the AJAX call and update the graph if the request is successfull/ready. So the graph update should be synchronized with your gathered Data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM