-1

I'm setting up a new server using a PLC. With this this server I must turn on/off the lights. At the moment I use a function to refresh the values coming from the PLC so the main page doesn't have to refresh constantly. I can already show a 1 or a 0 using an id and a label. I want to show a picture instead of a 1 or a 0.

I tried first with a 1 or a 0 instead of an image to simplify and see if that works. I thought by using L_Software and check if the value is 1 or 0 to return a 1 or 0.

      <label id="test"> dummy </label>
      <br>
      <label id="L_Refter">:="DB1 Lichten".Refter:</label>
      </div>
    </div>
  </body>
  <script type="text/javascript">
          $(document).ready(function(){
              $.ajaxSetup({ cache: false });
          setInterval(function() {
              $.getJSON("DataLichten.html", function(result){
                $('#L_Software').text(result.Software)
                $('#L_Refter').text(result.Refter)
              });
          },1000);
          });
          function lamp(waarde)
          {
            if (waarde=="1")
            {
              return 1;
            }
            if (waarde=="0")
             {
              return 0;
            }
          }
          document.getElementById("test").innerHTML = lamp(L_Software);
  </script>

I expect to show a 1 or a 0 instead of dummy. And later on make the 1 or 0 an image.

1 Answers1

-1
  <script type="text/javascript">
        let software; (or name it whatever you want)
        let refter;
          $(document).ready(function(){
              $.ajaxSetup({ cache: false });
          setInterval(function() {
              $.getJSON("DataLichten.html", function(result){
                $('#L_Software').text(result.Software)
                $('#L_Refter').text(result.Refter)
                software = result.Software;
                refter = result.Refter
              });
          },1000);
          });
          function lamp(waarde)
          {
            if (waarde=="1")
            {
              return 1;
            }
            if (waarde=="0")
             {
              return 0;
            }
          }
          document.getElementById("test").innerHTML = lamp(software);
  </script>
Qellson
  • 532
  • 2
  • 7
  • this reads like a game of spot-the-difference, not an answer. What did you change? WWhy should it solve the problem? – Quentin Apr 03 '19 at 09:56
  • If I'm interpreting this correctly, it won't work: https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Quentin Apr 03 '19 at 09:57
  • In the debug tool software has the value 1 or 0, but when compared it shows undefined. Added an else to see if function works. Then displayed the number I put in the else. – Maxim Happaerts Apr 03 '19 at 10:02