Jump to content

alert in AJAX


s_avinash_s

Recommended Posts

Hi

I am checking a value of a variable continuously,if the value exceeds 44 then i should popup an alert  window.

I tried the below code but its not working

<p class = "modify" id="systemp_pos"></p>
    
    <script>
    var sys_1;
    function systemp() {

      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) { 
	      document.getElementById("systemp_pos").innerHTML = this.responseText; 
            sys_1=this.responseText; 
            if(sys_1 > 44 )
            {
            alert("system temperature is increased");
            }
        }
      };
    xhttp.open("GET", "systemp_pos1.txt", true);
    xhttp.send();
    }

    setInterval(systemp, 1000);
    </script>

Please suggest

Link to comment
Share on other sites

Hi

this.responseText;

is the value always received from server and it is incremented always.

so am checking alert condition based on this value increment.

As of now 'systemp_pos1.txt' dont have a data in it. it is just for receiving at server as action=/systemp_pos1.txt

How to proceed 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...