0

I looked around for a while but I didn't find the information I'm looking for.

I have the following question. I've my code that using the getstatus function executes a settimeout loop every 10 seconds. In this loop the ajax takes some variable from a php page and set some variables values. My problem is with the value property of the g object.

I starts to define the g object and then its property g.value to be global.

In the gestatus function I get the value I want from the ajax call (TA_1) and then the setTimeout function starts in which I update the g.value to the new TA_1. But in this way it doesn't seem to update the property value in the g object. I found the way to put the entire object definition after the setTimeout function, but in this way it creates new object at every loop. There is a way to refresh an object property inside a setTimeout loop?

Thanks to everybody.

Cheers

  var g = new JustGage({
        id: "TA1",
        value: 0,
        min: 0,
        max: 1000,
        width: 100,
        height: 100,
        title: "Tsys A 1",
        });

    g.value = {};

    $(function() {

        getStatus();

    });

    function getStatus() {

        var TA_1    =   {};
        $.ajax({
        url: "getstatus2.php", 
        async: false,
        dataType: 'json',
        success: function(data) {
            TA_1    =   data.TsysA1;
            }
        });
        setTimeout("getStatus()",10000);
            g["value"] = TA_1;   
    }
hologhost
  • 23
  • 4
  • Stick this in:- `$('your_object').attr('attribute','value');` – Tilak Madichetti Apr 28 '16 at 17:26
  • You need to put it into the success: `success: function(data) { TA_1 = data.TsysA1; g["value"] = TA_1; setTimeout(getStatus,10000); } });` – mplungjan Apr 28 '16 at 17:33
  • Do you mean/intend to call `getStatus` in a recurrence? – IMTheNachoMan Apr 28 '16 at 17:38
  • "and then the setTimeout function starts in which I update the g.value to the new TA_1" -> that is not what your code is doing. You are asking for `getStatus()` to run after 10 seconds and (before `getStatus()` runs you'll update g["value"]. – IMTheNachoMan Apr 28 '16 at 17:41
  • That indent for `g["value"] = TA_1;` does not mean it'll run when the `getStatus()` above it runs... – IMTheNachoMan Apr 28 '16 at 17:42
  • Thanks everyone for the reply @TilakMadichetti, where I do have to put this? inside the success? – hologhost Apr 28 '16 at 18:03
  • @mplungjan the syntax you suggest is not working, I quite sure is my problem but I checked the modification quite well. – hologhost Apr 28 '16 at 18:03
  • @IMTheNachoMan that's right! – hologhost Apr 28 '16 at 18:03
  • @IMTheNachoMan I mean I was misinterpreting that g["value"] = TA_1; act after the settimeout. I'm missing something because I can't stille update this property. – hologhost Apr 28 '16 at 18:09
  • SOLVED - I found the object.refresh(value) call to refresh only the value without creating a new instance of the object. Thanks for all the hints – hologhost Apr 28 '16 at 19:05

0 Answers0