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

161
Views
Los elementos cargados a través de ajax no se pueden usar en jquery

Traté de poner mis tablas de datos en otro archivo y cargarlo a través de ajax, lamentablemente el envío del formulario ya no funciona.

Acabo de recibir el siguiente error: Uncaught TypeError: this.type is undefined , el valor de idRow aún se envía (puedo imprimirlo en la consola), por lo que en este momento no entiendo por qué dice que no está definido.

Cuando todo estaba en una sola página, lo siguiente funcionaba sin problemas:

Creación y envío de formularios después de hacer clic en el botón:

 <script> function submitForm(rowid) { form = document.createElement("form"); form.action = "save_tables.php"; / form.method = "post"; form.style.display = "none"; $("#"+rowid+" td").children().each(function() { if(this.type.substring(0,6) == "select") { input = document.createElement("input"); input.name = this.name; input.type = "hidden"; input.value = this.value; form.appendChild(input); } else { $(this).clone().appendTo(form); } }); document.body.appendChild(form); form.submit(); } </script>

Ejemplo para una entrada en la tabla

 <tr id="entry_4" class="row100 body"> <td><input type="text" name="lang"/></td> <td><input type="text" name="l_code"/></td> <td><input type="text" name="code"/></td> <td><button onclick="submitForm('entry_4')">Change</button></td> </tr>

Reemplacé la tabla con la siguiente y luego cargué las tablas a través de ajax.

 <div align="center" id="selection"> <button onclick="showTables('lang')">Lang</button> <button onclick="showTables('cat')">Cat</button> </div> <div id="target"> </div>
 <script> function showTables(showtype) { $.get(`load_tables.php?show=${showtype}`, function(data) { $('#target').html(data); }) } </script>
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Encontré el problema y una solución, aunque no sé por qué sucede.

Al cargar la tabla a través de ajax, this.type no está definido para algunas entradas, así que cambié if(this.type.substring(0,6) == "select") {

a lo siguiente para que funcione:

if(typeof this.type != 'undefined' && this.type.substring(0,6) == "select") {

Todas las entradas se envían (incluso si hay una seleccionada), por lo que funciona para mí

about 4 years ago · Santiago Gelvez 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!