views:

62

answers:

3

Hi,

I have one html page with links of chart whenever i refresh HTML paget the chart refreshs.

I heard from my friend that with the help of AJAX that chart will refresh automatically with given time interval without refreshing that html page.

please help me with the html code for the same.

Regards, Raj

+3  A: 

You could use the setInterval() method in javascript, along with a simple framework like jQuery for the AJAX.

It would look something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
  <head>
    <title>My AJAX Chart</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">

      $(document).ready(function(){
        setInterval("refreshChart", 5000); // Refresh every 5 seconds
      });

      function refreshChart() {
        $.get("myChart.php", function(data) {
          $("div.chartHolder").html(data);
        });
      }

    </script>
  </head>
  <body>

    <h1>My Chart</h1>
    <div class="chartHolder"></div>

  </body>
</html>
Jonathan Sampson
A: 

Since it sounds like you are new to JavaScript, I would recommend you take a look at the jQuery libraries, it can do what you want with a minimal of complication:

Something like this would work:

function updateChart() {
  $('#someTable tbody').load('updateChart.html');
}

$(function() {
  setInterval(updateChart, 20000);
});
altCognito
A: 

If you combine something like e.g. this; http://ra-ajax.org/Docs.aspx?class=Ra.Extensions.Widgets.Timer with this; http://ra-ajax.org/samples/Chart-Sample.aspx you'll easy get there.

Above samples are for .Net, but there exists similar constructs (and frameworks) also for other other platforms...

Thomas Hansen