Arduino update data without refreshing page.

Hello,
I need help with this code using an ESP8266. I’ve read that with ajax I can refresh a content without refreshing the whole page.
Because im very noobie Im looking if someone can help me update the “distancia” variable to the website using ajax since I dont know how to do it.

Thank you.

code arduino.txt (1.65 KB)

Ajax means you can send a javascript to the viewer's browser to run on it's own as a stand-alone instance. It would not be synchronized with your ESP8266 once it's been sent (the A in AJAX means asynchronous). If you want to maintain two-way communication, you probably want to look at Web Sockets. AJAX isn't as cool as it sounds.

You can use Javascript code sent to the browser to query the server at appropriate intervals and to update elements on the page with the data that it receives from the server.

The knowledge of how to do that is not particular to Arduinos or ESP8266s. My suggestion is that you learn how to do it with code on your PC and then when you know how it is done you can transfer your learning to the ESP8266. There will be many more online tutorials about web programming on a PC. You can easily set up a small server on your PC that an be accessed by the browser on the same PC. I use the Python Bottle web framework for my web programming. With it you can probably get a basic server working within 10 or 15 minutes.

The w3schools website is probably a good place to start learning about web programming.

...R