0

I have the following weird problem. I have an HTML page that has some RGraph gauges, which I want to update at regular intervals using Ajax.

The relevant code looks like this:

var update = function(){
    $.ajax({
        url : "update.php",
        dataType : 'json',
        success : function (json) {
            meterWind.set('value',json['hum']);                         
        }
    });
};
$('#test').click(function(){
    update();
});
setInterval(update, 2000);

The json output is ok, I checked it with an alert and it does return a value, for some reason the gauge was not updating. So to test it further I created a button "test" and set the function update() to trigger when test is clicked.

Now for some reason, when I click the test button, the gauge updates as it should - which suggests that the update() function works, just try clicking the test button several times.

However, no matter what I do and tried, when I trigger the function with the setInterval, the gauge does not change... weird, any suggestions?

http://meteotemplate.com/templateTest/testing/index.html

I also tried setting the interval on the "click" and when I put alert in the click, it alerts, but again, no update on the gauge.

var x = setInterval(function(){ $('#test').trigger("click");}, 3000);

1 Answers1

2

Reviewing the code that you provided, following change (success callback for your ajax request) made it to work. Meaning that basically after any change you need to update the UI by calling draw() method.

success : function (json) {
    meterWind.set('value',json['hum']);
    meterWind.draw();
}
leo.fcx
  • 6,137
  • 2
  • 21
  • 37