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

194
Views
¿Cómo puedo mostrar la entrada del cliente de área de texto en el sitio web sin cambiar la URL?

Estoy intentando implementar una característica en mi sitio web, donde un usuario puede ingresar un comentario en un área de texto y hacer que muestre el comentario, debajo del cuadro de comentarios. Para el backend estoy usando una botella. En este momento, la botella reconoce la entrada y, cuando se envía la entrada, se carga una nueva URL que muestra solo la entrada del área de texto. Cuando se envía, necesito que la entrada del área de texto se muestre debajo del cuadro del área de texto, sin cambiar la página web.

Aquí está la entrada de área de texto HTML

 <div> <p> Add a comment </p> <form action="/comment" method="post"> <textarea name="text"></textarea> <input type="submit" value="Submit"> </form> </div>

Botella en main.py

 @route('/comment', method = 'POST') def submit(): com = request.forms.get('text') print('Printing comment...') print(com) return com

index.js, (no estoy seguro de cómo integrar esta función)

 function loadCom () { var xhttp2 = new XMLHttpRequest(); xhttp2.onreadystatechange = function(){ if (this.readyState === 4 && this.status === 200){ console.log(this.response); document.getElementById("dcom").innerHTML = this.response; } }; xhttp2.open("GET", "/comment"); xhttp2.send(); return false }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Llame loadCom() desde un detector de eventos.

 document.querySelector("form").addEventListener("submit", e => { e.preventDefault(); // prevent reloading the page loadCom(); });

loadCom() necesita usar el método POST para enviar el valor del área de textarea al controlador.

 function loadCom () { var xhttp2 = new XMLHttpRequest(); xhttp2.onreadystatechange = function(){ if (this.readyState === 4 && this.status === 200){ console.log(this.response); document.getElementById("dcom").innerHTML = this.response; } }; xhttp2.open("POST", "/comment"); xhttp2.send('text=' + encodeURIComponent(document.querySelector('[name="text"]').value); return false }
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!