I figured out how to have a web server updated automatically without refresh using AJAX. within the webpage script, I have a variable (timeM)
</div>
Time is: <span id="timeM">0</span>
<script>
This variable is sent from a function like this:
setInterval(function()
{
getData();
}, 700);
function getData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("timeM").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "readALL", true);
xhttp.send();
}
which gathers data from a "regular" function like this:
void handleALL() {
timeClient.update();
Second = (timeClient.getSeconds());
Minute = (timeClient.getMinutes());
Hour = (timeClient.getHours());
if (Hour > 12){
Hour = Hour - 12;
}
String nValue = String (Hour);
String mValue = String (Minute);
String sValue = String (Second);
String AllDev = String(Hour) + ":" + String(Minute) + "::" + String(Second);
server.send(200, "text/plain", AllDev); //Send ADC values only to client ajax request
}
What I don't understand is the only way the page is updated is if the variable is changed from within the handleALL();
How do you make something that is read/changed within void loop() make changes to the webserver via AJAX?
Thanks!