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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...