Page 1 of 1

Read back value from Ajax?

Posted: Thu Dec 23, 2021 5:34 pm
by MJU20
Hi there,

I'm playing around with an ESP32 Wroom and came across a trick I've used in the past.

The HTML code shows the pressed button without reloading the whole page, but is it possible to read back the state of the button value?
In the webpage the pressed button is shown by the variable "butt", but can I read back this value to the ESP32 to act on? Or do I need to reload the page?

Code: Select all

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

$("#btn1").click(function(){
$("#butt").html("Button 1");
});

$("#btn2").click(function(){
$("#butt").html("Button 2");
});

$("#btn3").click(function(){
$("#butt").html("Button 3");
});
});
</script>
</head>
<body>
<button type="button" class="btn btn-danger" id="btn1">Button 1</button>
<button type="button" class="btn btn-danger" id="btn2">Button 2</button>
<button type="button" class="btn btn-danger" id="btn3">Button 3</button>
<h4>Gedrukte knop: <span id="butt">Geen Button</span></h4>
</body>
</html>