0

I have a simple idea of controller on my network. Every pc work with CORS.

in my panel web page, this code work fine:

        $.get('http://192.168.20.14/?q=.ping',
        function(data){
            j_res='Dead';
            if(data=='pong')
                j_res='Live';
            $('#sem_elm14').append(j_res)});

but this is for one pc.

If I repeat all .get for any pc that I want to control using static name (sem_elm14), work fine.

But if I write a loop, I think that a value of array in function(data) will be lost or boh:

    var j_elm=new Array (61,14,62)
for (i=0;i<j_elm.length;i++){
    $.get('http://192.168.20.'+j_elm[i]+'/?q=.ping',
        function(data){
            if(data=='pong')
                j_res='Live'
            $('#sem_elm'+j_elm[i]).append(j_res)});
}

Any idea?

Thank you for any suggestion

Ste

Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
Ste
  • 33
  • 6
  • I think that not the same becouse .get work in asynchronous mode. I tried to follow the advice, but it does not work – Ste Jun 11 '14 at 16:41
  • The same approach works, see http://jsfiddle.net/kkxrF/ for a working example – Turch Jun 11 '14 at 16:54
  • Made a small update to move the array access inside the `makeRequest` function, since you need the value of `i` for the callback, not just the array value: http://jsfiddle.net/kkxrF/2/ – Turch Jun 11 '14 at 17:00

0 Answers0