Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
function attachEvents() { let authorInp = document.getElementById("author"); let contentInp = document.getElementById("content"); let sendBtn = document.getElementById("submit"); let refreshBtn = document.getElementById("refresh"); let chatBox = document.getElementById("messages"); console.log(chatBox) sendBtn.addEventListener("click", function () { let authorName = authorInp.value; let msgText = contentInp.value; let msgObj = { author: authorName, content: msgText } console.log(msgObj) fetch('https://rest-messanger.firebaseio.com/messanger.json', { method: 'post', headers: { 'Content-type': 'application/json' }, body: JSON.stringify(msgObj), }) contentInp.value=""; }) refreshBtn.addEventListener("click", function () { fetch('https://rest-messanger.firebaseio.com/messanger.json') .then(res => res.json()) .then(data => { let arrayResponse = Object.entries(data); arrayResponse.forEach(obj => { console.log(obj) let composedMessage = `${obj[1].author}: ${obj[1].content}` chatBox.textContent += `${composedMessage}\n`; authorInp.value=""; contentInp.value=""; }); }) }) } attachEvents();
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)