Jump to content
s_avinash_s

alert in AJAX

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

Share this post


Link to post
Share on other sites

This code seems to work fine, are you making sure that your 'systemp_pos1.txt' has the number 45 in it.

Share this post


Link to post
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 

Share this post


Link to post
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

×