nodeMCU和ajax代替刷新一个元素,重复整个网页。

huangapple go评论89阅读模式
英文:

nodeMCU and ajax instead of refresh one element repeats whole web-page

问题

I need help with reloading two elements at my webpage. I have small electronics and its brain is NodeMCU. I need there two outputs (which are connected to relays) and two inputs.

With inputs I want to update periodically (without manual reloading the webpage) two elements of the page according to two digital inputs. For that, I use ajax. I have found some hints: http://www.martyncurrey.com/esp8266-and-the-arduino-ide-part-8-auto-update-webpage/

Almost everything works perfectly (outputs and inputs). Only one problem is that after a timeout, the whole webpage is repeated and is shown twice in the web browser.

Sorry for adding my code as an image (below). But when I insert it here as text, many parts of the code are recognized as HTML tags and are not shown.

I have placed this code on my webpage: http://fiksoftware.4fan.cz/bojler.ino

Could anybody please give me any advice on what is wrong with my code (below).

Thanks a lot to all.

英文:

I need help with reloading two elements at my webpage. I have small electronics and its brain is NodeMCU. I need there two outputs (which are connected to relays) and two inputs.

With inputs I want update periodically (without manual reloading webpage) two elements of page according two digital inputs. For that I use ajax. I have found some hints:
http://www.martyncurrey.com/esp8266-and-the-arduino-ide-part-8-auto-update-webpage/

Almost everything works perfect (outputs and inputs). Only one problem is that after time out is whole web page repeated and is in web-browser shown twice.

Sorry for adding my code as image (bellow). But when I insert here as a text - may parts of code is recognized as html tag and is not shown.
I have placed this code to my webpages: http://fiksoftware.4fan.cz/bojler.ino

Please could anybody give me any advice what is wrong in my code (bellow).

Thanks a lot to all.
nodeMCU和ajax代替刷新一个元素,重复整个网页。

my code:

答案1

得分: 0

我找到了解决方案。我的朋友帮助了我!

问题出在我在请求数据后发送整个页面。

所以在创建网页的开头,我添加了一个条件来决定是否需要数据还是整个页面:

nodeMCU和ajax代替刷新一个元素,重复整个网页。

英文:

I have found solution. My friend helps me!

problem was in that I have sent whole page after request of data.

So I have at the begining of creating web page added if which decide if I need data or whole page:

nodeMCU和ajax代替刷新一个元素,重复整个网页。

huangapple
  • 本文由 发表于 2023年4月10日 22:51:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定