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

98
Views
La aplicación Spring Boot no ejecutará código JavaScript

Estoy creando una aplicación web Spring que permite enviar fragmentos de código a una base de datos. Tengo un punto final HTML donde puede ingresar texto y hacer clic en un botón para que el texto se envíe a una base de datos. Aquí está el código html:

ingrese la descripción de la imagen aquí

El script send.js es responsable de tomar el texto de entrada y enviarlo a json. Aquí está el código send.js:

 function send() { let object = { "code": document.getElementById("code_snippet").value }; let json = JSON.stringify(object); let xhr = new XMLHttpRequest(); xhr.open("POST", '/api/code/new', false) xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8'); xhr.send(json); if (xhr.status == 200) { alert("Success!"); } }

Por alguna razón cuando presiono el botón no pasa nada. Intenté depurar la aplicación y parece que no ejecuta el código js. Tuve algunos problemas incluso para acceder a send.js en html al principio, intellij simplemente no podía verlo por alguna razón. Esta es mi estructura de recursos:

ingrese la descripción de la imagen aquí

¿Qué estoy haciendo mal aquí?

Editar: intenté agregar esto en lugar de solo verificar si el estado es igual a 200 y no recibo ninguna de las alertas

 if (xhr.status != 200) { alert("Something went wrong!"); } else if (xhr.status == 200){ alert("Success!"); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En el archivo html tiene id="code-snippet", y en el js tiene "code_snippet", intente solucionarlo

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!