Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

javascript - How to allow output onto webpage from console log mqtt message

A few questions and I apologise if they seem unprofessional, I am a beginner programmer. But I would really appreciate any and all help you'd provide!

  1. Currently, I have used an MQTT program to receive messages over websockets. I can view my message in the console.log but I would like to ask how can I convert it to the html output messages. is it by document.getElementById ? or is there a more better way to do that?

  2. What is the benefit of using JSON for the messages?

  3. What is the purpose of using variable.push(entry.anothervariable) is the push entry better and perhaps I should use an array to store the messages and then push them out?

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Without context answering these questions are not really a good fit for Stackoverflow, but here are some answers.

  1. Without the context of what frameworks you are using, yes finding an element with document.getElementById() and then updating it's content with .innerText or .innerHTML is probably the simiplest way forward

  2. Sending messages encoded as JSON when working with JavaScript means that you don't need to worry about parsing any other encoding format, you can directly access fields using the native JavaScript Object Model.

  3. This question is totally unanswerable with out any context for what you are actually working with. The .push() method is how you append an item to an existing array.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] 怎么让ant的ant-message组件生成的元素在

1.4m articles

1.4m replys

5 comments

57.0k users

...