Closed arimukhlas closed 10 months ago
case close, I use this on script.
on sketch
myWebServer.addHandler("/getValues", HTTP_GET, getActualValue);
...
void getActualValue() {
StaticJsonDocument<256> doc;
String payload;
doc["sunrise"] = "08:00";
doc["sunset"] = "20:00";
serializeJsonPretty(doc, payload);
myWebServer.webserver->send(200, "text/json", payload);
}
on additional js script
setInterval(getActualValues,5000);
function getActualValues() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var data = JSON.parse(this.responseText);
document.getElementById("sunrise-actual").innerHTML = data.sunrise;
document.getElementById("sunset-actual").innerHTML = data.sunset;
}
};
xhttp.open("GET", "/getValues2", true);
xhttp.send();
}
Hi @cotestatnt
I want to show json value to customElement.h every first time I open the page. I found this from you and I follow the instruction
so I add handler and function to customHTML.ino like this
and add script to customElement.h like this
but nothing happen. So Is it correct that the steps I have used?