Shop OBEX P1 Docs P2 Docs Learn Events
Multiple AJAX requests from single page- how to??? — Parallax Forums

Multiple AJAX requests from single page- how to???

RforbesRforbes Posts: 281
edited 2013-02-27 04:50 in Accessories
Heya folks,

I'm trying to sort out a problem and not getting very far. My goal is to update different sections of a web page at different times- via AJAX.

My code is pretty straight forward on the spinneret side (W5100)...
PRI Dispatcher(id)
'' HTTP request handler

  ''Live Data Output                      
  if(strcomp(Request.GetPathNode(id, 0), string("First")))

     Update_Time(id,0,46)

     return

  if(strcomp(Request.GetPathNode(id, 0), string("Second")))
     Update_Data(id)

     return

But I'm struggling with the javascript side of things.

My javascript is: (called via the <script src=test.js</script> section on the htm file.)
function DataLoop(){
         var req1 = getXmlHttpRequestObject();
         setTimeout(function(){getData1('First')},2000);

         var req2 = getXmlHttpRequestObject();
         setTimeout(function(){getData2('Second')},4000);
        }

function getData1(resource){
     
    // handle the case where a querystring is not detected
    var char = "&";
     if(resource.indexOf("?", 0) == -1) {
        char = "?";
                                       }
        
    if (req1.readyState == 4 || req1.readyState == 0) {
         req1.open("GET", resource + char + 'ms=' + new Date().getTime(), false);
         req1.onreadystatechange = handleResponse;
         req1.send(null);
         return false;
    }
        }

    function handleResponse() {
         if (req1.readyState == 4) 
         {
            parseState(req1.responseXML);
         }
    } 

    function parseState(xDoc){
        if(xDoc == null)
            return

                // IO data starts here
                var target = document.getElementById("Date");
                target.innerHTML = xDoc.getElementsByTagName("Date")[0].childNodes[0].nodeValue;
                var target = document.getElementById("Time");
                target.innerHTML = xDoc.getElementsByTagName("Time")[0].childNodes[0].nodeValue;
}

function getData2(resource){
     
    // handle the case where a querystring is not detected
    var char = "&";
     if(resource.indexOf("?", 0) == -1) {
        char = "?";
                                       }
        
    if (req2.readyState == 4 || req2.readyState == 0) {
         req2.open("GET", resource + char + 'ms=' + new Date().getTime(), false);
         req2.onreadystatechange = handleResponse;
         req2.send(null);
         return false;
    }
        }

    function handleResponse() {
         if (req2.readyState == 4) 
         {
            parseState(req2.responseXML);
         }
    } 

    function parseState(xDoc){
        if(xDoc == null)
            return

                // IO data starts here
                var target = document.getElementById("Speed");
                target.innerHTML = xDoc.getElementsByTagName("Speed")[0].childNodes[0].nodeValue;
                var target = document.getElementById("Pressure");
                target.innerHTML = xDoc.getElementsByTagName("Pressure")[0].childNodes[0].nodeValue;
}

function getXmlHttpRequestObject() {
     if (window.XMLHttpRequest) {
         return new XMLHttpRequest();
     } else if (window.ActiveXObject) {
         return new ActiveXObject("Microsoft.XMLHTTP");
     } else {
         alert("Your Browser does not support AJAX- Please upgrade to latest version of Firefox.");
     }
}

setInterval (function(){DataLoop},6000);

I keep getting a "req2 is not defined" error in firefox error console, and the web page doesn't update the values. On the spinneret side, I use PST to verify that the appropriate method is called, and it is indeed called. So I know xml data is being spat out, but there is something wrong with the way I'm trying to use AJAX here.

Any advice, ideas please? I'd sure appreciate it!

Thanks in advance!
Robert

Comments

  • ZootZoot Posts: 2,227
    edited 2013-02-25 07:26
    You're defining "handleResponse" and "parseState" twice -- so you have no way to parse the response on two requests.

    You can either give all definitions unique names, or fold the script for both requests into those functions.
  • RforbesRforbes Posts: 281
    edited 2013-02-25 07:59
    Zoot- Ah, shoot... ok. I'm still really new to javascript and was sort of thinking it would magically work. :smile:

    Thanks very much! I will try some more tonight when I get a chance and see what I come up with.

    Robert
  • ZootZoot Posts: 2,227
    edited 2013-02-25 08:03
    Think about it -- you have a function "handleResponse" -- the first definition checks if req1 is done/ready; the second definition checks if req2 is done/ready. Only one definition of the function will actually be in use at any given time. As you define those functions within a function, it will depend on when the parent function is called. Unlike variables, which can be local to the function or global in scope, in JavaScript, all functions are "global". I'm over simplifying a bit, but these are rules of thumb you can follow.
  • RforbesRforbes Posts: 281
    edited 2013-02-25 08:18
    That's great to know. THANKS for explaining that in laymans terms... Yep, I was kind of thinking the functions handleResponse and parseState would act like individual instances, or locally.

    So... that brings up another question. if I changed getXmlHttpRequestObject so that my req1 variable is defined via getXmlHttpRequestObject1 and my req2 variable is defined via getXmlHttpRequestObject2, and made the appropriate changes to handleResponse and parseState by making them 1 and 2- would I then be able to skip using the setTimeout function? I guess what I'm asking is- if I don't use the setTimeout, both req1 and req2 will fire at just about the same time.... so I'm not sure how the spinneret would respond to that? Will it just que up the second one and run when it's able? I hope my question makes sense. Sorry if it doesn't!
  • ZootZoot Posts: 2,227
    edited 2013-02-25 08:35
    No, you don't need two getXmlHttpRequestObject -- you separate this function when you make req1 = or req2 = to that function. Each is an "instance" of the function with a new "name" -- req1 or req2.

    You can just setInterval for each, without the dataloop. Whether or not you set timeouts is up to you.
  • Mike GMike G Posts: 2,702
    edited 2013-02-25 08:37
    So... that brings up another question. if I changed getXmlHttpRequestObject so that my req1 variable is defined via getXmlHttpRequestObject1 and my req2 variable is defined via getXmlHttpRequestObject2, and made the appropriate changes to handleResponse and parseState by making them 1 and 2- would I then be able to skip using the setTimeout function? I guess what I'm asking is- if I don't use the setTimeout, both req1 and req2 will fire at just about the same time.... so I'm not sure how the spinneret would respond to that? Will it just que up the second one and run when it's able? I hope my question makes sense. Sorry if it doesn't!
    It creates a mess. Retrieve all the values with one request wrapped in one XML doc. If the XML returned has an empty node, don't update the HTML. Otherwise, return different XML docs but give each a name (ID) . That way you sort out the type when it is received and update the HTML accordingly.
  • RforbesRforbes Posts: 281
    edited 2013-02-25 08:45
    Mike, Zoot- thanks so much. Great info. I gotta scoot, duty calling. But I'm going to keep working on this tonight and see how it goes. Ya'll have a great day!!

    Robert
  • RforbesRforbes Posts: 281
    edited 2013-02-26 17:40
    Mike, I think I get what you're saying, but I'm not quite sure what you mean by "return different XML docs but give each a name (ID)" ... can you explain that a little more please?

    To help clarify my application, the reason I am trying to do multiple ajax thingies (that's the technical term, btw) is because in doing so, I can greatly reduce the RXTX_BUFFER and TEMP_BUFFER size, thereby giving me more room to play with fabulous, mind boggling, snazzy methods and such. Or at least I have more memory space to create such things one day! :cool:

    As a minor update, I created this .js and it seems to be working pretty well. I'm trying to bone up on using a callback function (I think that's what I need, not certain) so that the various ajax calls will only fire when the previous one is proven to be complete. If you have some good advice I could really use it! (My wife told me to stop being such a geek... I don't need more of that advice! haha!)
    //Need to run three functions 1 second apart, over and over.
             var req0 = getXmlHttpRequestObject();
             var req1 = getXmlHttpRequestObject();
          var req2 = getXmlHttpRequestObject();
    
             setInterval (function(){DataLoop()},490);
    
    function DataLoop(){
    
             setTimeout(function(){getData0('DateTime')},100);
             setTimeout(function(){getData1('LD1')},200);
             setTimeout(function(){getData2('LD2')},300);
    }
    
    function getXmlHttpRequestObject() {
         if (window.XMLHttpRequest) {
             return new XMLHttpRequest();
         } else if (window.ActiveXObject) {
             return new ActiveXObject("Microsoft.XMLHTTP");
         } else {
             alert("Your Browser does not support AJAX- Please upgrade to latest version of Firefox.");
         }
    }
    
    function getData0(resource){
                  
        // handle the case where a querystring is not detected
        var char = "&";
         if(resource.indexOf("?", 0) == -1) {
            char = "?";
                                           }
            
        if (req0.readyState == 4 || req0.readyState == 0) {
             req0.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
             req0.onreadystatechange = handleResponse0;
             req0.send(null);
             return false;
        }
    }
    
        function handleResponse0() {
             if (req0.readyState == 4) 
             {
                parseState0(req0.responseXML);
             }
    } 
    
        function parseState0(xDoc){
            if(xDoc == null)
                return
    
                    // IO data starts here
                    var target = document.getElementById("Date");
                    target.innerHTML = xDoc.getElementsByTagName("Date")[0].childNodes[0].nodeValue;
                    var target = document.getElementById("Time");
                    target.innerHTML = xDoc.getElementsByTagName("Time")[0].childNodes[0].nodeValue;
    }
    function getData1(resource){
         
        // handle the case where a querystring is not detected
        var char = "&";
         if(resource.indexOf("?", 0) == -1) {
            char = "?";
        }
            
         if (req1.readyState == 4 || req1.readyState == 0) {
             req1.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
             req1.onreadystatechange = handleResponse1;
             req1.send(null);
             return false;
         }
    }
    
        function handleResponse1() {
             if (req1.readyState == 4) 
             {
                parseState1(req1.responseXML);
             }
    } 
    
        function parseState1(xDoc){
            if(xDoc == null)
                return
    
                    // IO data starts here
                    var target = document.getElementById("IOS0");
            target.innerHTML = xDoc.getElementsByTagName("IOS0")[0].childNodes[0].nodeValue;
                    var target = document.getElementById("IOS1");            
            target.innerHTML = xDoc.getElementsByTagName("IOS1")[0].childNodes[0].nodeValue;
                    
                    var target = document.getElementById("IOS2");            
            target.innerHTML = xDoc.getElementsByTagName("IOS2")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
                    
                    var target = document.getElementById("IOS3");            
            target.innerHTML = xDoc.getElementsByTagName("IOS3")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
                    
                    var target = document.getElementById("IOS4");            
            target.innerHTML = xDoc.getElementsByTagName("IOS4")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS5");            
            target.innerHTML = xDoc.getElementsByTagName("IOS5")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS6");            
            target.innerHTML = xDoc.getElementsByTagName("IOS6")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS7");            
            target.innerHTML = xDoc.getElementsByTagName("IOS7")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS8");            
            target.innerHTML = xDoc.getElementsByTagName("IOS8")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS9");            
            target.innerHTML = xDoc.getElementsByTagName("IOS9")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS10");            
            target.innerHTML = xDoc.getElementsByTagName("IOS10")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS11");            
            target.innerHTML = xDoc.getElementsByTagName("IOS11")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";  
    
                    var target = document.getElementById("IOS12");            
            target.innerHTML = xDoc.getElementsByTagName("IOS12")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS13");            
            target.innerHTML = xDoc.getElementsByTagName("IOS13")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS14");            
            target.innerHTML = xDoc.getElementsByTagName("IOS14")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS15");            
            target.innerHTML = xDoc.getElementsByTagName("IOS15")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS16");            
            target.innerHTML = xDoc.getElementsByTagName("IOS16")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS17");            
            target.innerHTML = xDoc.getElementsByTagName("IOS17")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS18");            
            target.innerHTML = xDoc.getElementsByTagName("IOS18")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS19");            
            target.innerHTML = xDoc.getElementsByTagName("IOS19")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS20");            
            target.innerHTML = xDoc.getElementsByTagName("IOS20")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS21");            
            target.innerHTML = xDoc.getElementsByTagName("IOS21")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS22");            
            target.innerHTML = xDoc.getElementsByTagName("IOS22")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS23");            
            target.innerHTML = xDoc.getElementsByTagName("IOS23")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS24");            
            target.innerHTML = xDoc.getElementsByTagName("IOS24")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS25");            
            target.innerHTML = xDoc.getElementsByTagName("IOS25")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS26");            
            target.innerHTML = xDoc.getElementsByTagName("IOS26")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS27");            
            target.innerHTML = xDoc.getElementsByTagName("IOS27")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS28");            
            target.innerHTML = xDoc.getElementsByTagName("IOS28")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS29");            
            target.innerHTML = xDoc.getElementsByTagName("IOS29")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS30");            
            target.innerHTML = xDoc.getElementsByTagName("IOS30")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
     
                    var target = document.getElementById("IOS31");            
            target.innerHTML = xDoc.getElementsByTagName("IOS31")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    }
    
    function getData2(resource){
    
        // handle the case where a querystring is not detected
        var char = "&";
         if(resource.indexOf("?", 0) == -1) {
            char = "?";
        }
            
         if (req2.readyState == 4 || req2.readyState == 0) {
             req2.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
             req2.onreadystatechange = handleResponse2;
             req2.send(null);
             return false;
         }
    }
    
        function handleResponse2() {
             if (req2.readyState == 4) 
             {
                parseState2(req2.responseXML);
             }
    } 
    
        function parseState2(xDoc){
            if(xDoc == null)
                return
    
                    // IO data starts here
                    var target = document.getElementById("IOS32");            
            target.innerHTML = xDoc.getElementsByTagName("IOS32")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";    
       
                    var target = document.getElementById("IOS33");            
            target.innerHTML = xDoc.getElementsByTagName("IOS33")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";    
    
                    var target = document.getElementById("IOS34");            
            target.innerHTML = xDoc.getElementsByTagName("IOS34")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";    
          
                    var target = document.getElementById("IOS35");            
            target.innerHTML = xDoc.getElementsByTagName("IOS35")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";          
    
                    var target = document.getElementById("IOS36");            
            target.innerHTML = xDoc.getElementsByTagName("IOS36")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
       
                    var target = document.getElementById("IOS37");            
            target.innerHTML = xDoc.getElementsByTagName("IOS37")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS38");            
            target.innerHTML = xDoc.getElementsByTagName("IOS38")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS39");            
            target.innerHTML = xDoc.getElementsByTagName("IOS39")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS40");            
            target.innerHTML = xDoc.getElementsByTagName("IOS40")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";
    
                    var target = document.getElementById("IOS41");            
            target.innerHTML = xDoc.getElementsByTagName("IOS41")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS42");            
            target.innerHTML = xDoc.getElementsByTagName("IOS42")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS43");            
            target.innerHTML = xDoc.getElementsByTagName("IOS43")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS44");            
            target.innerHTML = xDoc.getElementsByTagName("IOS44")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>"; 
    
                    var target = document.getElementById("IOS45");            
            target.innerHTML = xDoc.getElementsByTagName("IOS45")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";                                        
                                   
                    var target = document.getElementById("IOS46");            
            target.innerHTML = xDoc.getElementsByTagName("IOS46")[0].childNodes[0].nodeValue;
                    if (target.innerHTML == 1) target.innerHTML="<img src=run.jpg>";
                    else if (target.innerHTML == 0) target.innerHTML="<img src=stop.jpg>";                                
    /*        
            var target = document.getElementById("IOS47");            
            target.innerHTML = xDoc.getElementsByTagName("IOS47")[0].childNodes[0].nodeValue;        
            
            var target = document.getElementById("IOS48");            
            target.innerHTML = xDoc.getElementsByTagName("IOS48")[0].childNodes[0].nodeValue; 
    
                   var target = document.getElementById("IOS49");            
            target.innerHTML = xDoc.getElementsByTagName("IOS49")[0].childNodes[0].nodeValue;         
            
            var target = document.getElementById("IOS50");            
            target.innerHTML = xDoc.getElementsByTagName("IOS50")[0].childNodes[0].nodeValue; 
    
            var target = document.getElementById("IOS51");            
            target.innerHTML = xDoc.getElementsByTagName("IOS51")[0].childNodes[0].nodeValue; 
    
                var target = document.getElementById("IOS52");            
                target.innerHTML = xDoc.getElementsByTagName("IOS52")[0].childNodes[0].nodeValue; 
            
                var target = document.getElementById("IOS53");            
            target.innerHTML = xDoc.getElementsByTagName("IOS53")[0].childNodes[0].nodeValue;        
            
                var target = document.getElementById("IOS54");            
                target.innerHTML = xDoc.getElementsByTagName("IOS54")[0].childNodes[0].nodeValue;        
                                                       
                 var target = document.getElementById("IOS55");            
                target.innerHTML = xDoc.getElementsByTagName("IOS55")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS56");            
                target.innerHTML = xDoc.getElementsByTagName("IOS56")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS57");            
                target.innerHTML = xDoc.getElementsByTagName("IOS57")[0].childNodes[0].nodeValue;
            
                var target = document.getElementById("IOS58");            
                target.innerHTML = xDoc.getElementsByTagName("IOS58")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS59");            
                target.innerHTML = xDoc.getElementsByTagName("IOS59")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS60");            
                target.innerHTML = xDoc.getElementsByTagName("IOS60")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS61");            
                target.innerHTML = xDoc.getElementsByTagName("IOS61")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS62");            
                 target.innerHTML = xDoc.getElementsByTagName("IOS62")[0].childNodes[0].nodeValue;
    
                var target = document.getElementById("IOS63");            
                target.innerHTML = xDoc.getElementsByTagName("IOS63")[0].childNodes[0].nodeValue;
    */
    }
    
    
    //setInterval(function(){getData0('DateTime')},2000);
    //setInterval(function(){getData1('LD1')},2000);
    //setInterval(function(){getData2('LD2')},2000);
    
    
    
    

    Robert
  • Mike GMike G Posts: 2,702
    edited 2013-02-26 21:01
    Sounds like like you need an array. The attached is a simple array example that you should be able to reuse.
  • LtechLtech Posts: 370
    edited 2013-02-27 01:30
    getios:

    Works in Safari (win & osx)
    Not working in explorer & chrome .

    LTech
  • Mike GMike G Posts: 2,702
    edited 2013-02-27 04:13
    Ltech, you are correct! getios does not run in IE and Chrome from the file system you must drop the getios folder in a virtual directory and run it as an application. If you checked the error, you would see IE is complaining about cross site scripting...

    In Windows IIS 6.5
    • Drop the unzipped getios folder in C:\inetpub\wwwroot
    • Open Internet Information Services (start -> run -> type inetmgr)
    • Open the Web Sites node
    • Open the Default Web Site node
    • Find getios
    • Right click the folder and select Properties
    • In the Directory tab find the Create button and click the button.
    • Click Ok
    • Open the getios in the Internet Information Services window
    • Right Click getios.htm and select Browse.

    IIS 7 is similar. When you right click the folder in Internet Information Services you can select Create Application, if memory serves...

    BTW, post #10 and getios demos how to handle an array of values while making the XML light weight and reusable. This approach will save precious Prop Memory. I hope that concept was conveyed.
  • RforbesRforbes Posts: 281
    edited 2013-02-27 04:15
    I'll give a try at making this work. Thanks again man.... owe ya one!

    Robert
  • Mike GMike G Posts: 2,702
    edited 2013-02-27 04:42
    I updated the file in getios.htm. Here is the change...

    Was...
    <script language="javascript" type="application/javascript">
    

    Updated To...
    <script language="javascript" type="text/javascript">
    

    This will cause IE to pop up a warning when the file is opened and will generate an Access is Denied error if the link is clicked. Still can't run the demo from the file system but at least the error message is a bit more descriptive.
  • Mike GMike G Posts: 2,702
    edited 2013-02-27 04:50
    I'll give a try at making this work. Thanks again man.... owe ya one!
    The key is reusable XML. What I did not show was how to distinguish between XML docs by reading the app node id attribute.
    <app id="myApp">
    

    I'll leave that up to you. Let me know if you need help. Use the two files attached to #10 to build a simple testing rig. Verify functionality before implementing on the prop. It will save you a lot of time.
Sign In or Register to comment.