s_avinash_s Posted October 16, 2018 Share Posted October 16, 2018 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 More sharing options...
dsonesuk Posted October 16, 2018 Share Posted October 16, 2018 So this.responseText is a number value that increments every request yes! Link to comment Share on other sites More sharing options...
Funce Posted October 16, 2018 Share Posted October 16, 2018 This code seems to work fine, are you making sure that your 'systemp_pos1.txt' has the number 45 in it. Link to comment Share on other sites More sharing options...
s_avinash_s Posted October 17, 2018 Author Share Posted October 17, 2018 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 More sharing options...
dsonesuk Posted October 17, 2018 Share Posted October 17, 2018 Try this instead sys_1=parseInt(this.responseText); Link to comment Share on other sites More sharing options...
s_avinash_s Posted October 17, 2018 Author Share Posted October 17, 2018 Thank you somuch this works Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now