Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
¿Cómo puedo ver un texto adjunto al instante en un cliente diferente sin usar socket.io?[node.js]

Estoy creando una aplicación web simple en la que puedes publicar frases. Hace todo lo que quiero, excepto mostrar lo que otra persona agregó al sitio al instante. Sé que podría usar socket.io para eso, pero me pregunto si podría lograr lo mismo sin usarlo para mantener el sitio lo más simple posible. aquí está el código

 //script.js file fetch('https://server.jonaso1.repl.co/').then(response => response.json()) .then(data => { for (let i = 0; i < data.length; i++) prependPhrase(data[i]); }); //this loads saved stuff on the page when you access it form.onsubmit = (e) => { //this posts input values on server (I omitted var declarations) e.preventDefault(); var data = { [input.name1]:input1.value, [input2.name]:input2.value, [input3.name]:input3.value, }; prependPhrase(data); fetch('https://server.jonaso1.repl.co/frases', { method: "POST", body: JSON.stringify(data), headers: {"Content-type": "application/json"} }) }; function prependPhrase(data) {//just the function that puts the text on site const p = document.createElement('p'); const span = document.createElement('span'); p.setAttribute('class', 'p'); container.prepend(p); p.append(`${data.user} enviou : `) p.append(span); span.append(`${data.frasefavorita}`) p.append(` - ${data.autor}`) } //server.js file mongoose.connect(mongoDB).then(() => console.log('database conectada')).catch((err) => console.log(err)); app.use(cors()); app.use(express.urlencoded({extended:true})); app.use(express.json()); app.get('/', (req, res) => { phrase.find().then(result => {//this responds to get reqs with mongodb res.send(JSON.stringify(result)) }) }); app.post('/frases', (req, res) => { //this saves more phrases in mongodb const frase = new phrase(req.body); frase.save().then(() => console.log('frase salva')); }); app.listen(3000, () => { console.log('listening on 3000')});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que estás buscando encuestas largas. Aquí hay una buena explicación con un ejemplo https://javascript.info/long-polling

Aquí hay una comparación de encuestas, sockets y sse https://codeburst.io/polling-vs-sse-vs-websocket-how-to-choose-the-right-one-1859e4e13bd9

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!