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

189
Views
codeigniter devuelve datos de búsqueda del controlador para verlos a través de una solicitud de Ajax

Cargo la vista en la que quiero mostrar el registro de recuperación de la base de datos a través de la solicitud ajax JSON. Pero no muestra el registro.

Aquí está mi código de vista

 <div class="col-md-6" id="hodm_table"> <table class="table table-striped table-hover table-responsive"> <thead> <tr> <th>Task Name</th> <th>Director</th> <th>Duration</th> <th>Status</th> </tr> </thead> <tbody> <?php foreach($result as $hodm) { ?> <tr> <td><?php echo $hodm->t_name;?></td> <td><?php echo $hodm->director;?></td> <td><?php echo $hodm->duration;?></td> <td><?php echo $hodm->status;?></td> <?php } ?> </tbody> </table> </div> </div> <script type='text/javascript' language='javascript'> $(document).ready(function(){ $.ajax({ url:"<?php echo base_url();?>digital/dashboard/dig_short_hodm_table", type: 'POST', dataType: 'JSON', success:function (data) { $('#hodm_table').html(data); } }); event.preventDefault(); }); </script>

Aquí está mi modelo

 public function get_hodm() { return $this->db->get("hodm"); }

Aquí está mi controlador

 public function dig_short_hodm_table(){ $data['result']=$this->pojo->get_hodm(); return json_encode($data); }

Cuando cargo mi página, muestra el error.

 Message: Undefined variable: result

Cuando la vista lo cargue, quiero obtener el registro de la base de datos y mostrarlo en las tablas de vista.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Actualiza tu modelo:

 public function get_hodm(){ return $this->db->get("hodm")->result(); }

Tu controlador:

 public function dig_short_hodm_table(){ $result_html = ''; $result_set = $this->pojo->get_hodm(); foreach($result_set as $result) { $result_html .= ' <tr> <td>' . $result->t_name . '</td> <td>' . $result->director . '</td> <td>' . $result->duration . '</td> <td>' . $result->status . '</td> </tr>'; } echo json_encode($result_html); }

Finalmente tu opinión:

 <div class="col-md-6" id="hodm_table"> <table class="table table-striped table-hover table-responsive"> <thead> <tr> <th>Task Name</th> <th>Director</th> <th>Duration</th> <th>Status</th> </tr> </thead> <tbody id="hodm_results"> </tbody> </table> </div> <script type='text/javascript' language='javascript'> $(document).ready(function(){ $.ajax({ url:"<?php echo base_url();?>digital/dashboard/dig_short_hodm_table", type: 'POST', dataType: 'JSON', success:function (data) { $('#hodm_results').html(data); } }); event.preventDefault(); }); </script>
over 4 years ago · Santiago Trujillo Report

0

debes cambiar asi

 public function get_hodm() { return $this->db->get("hodm")->result(); }
over 4 years ago · Santiago Trujillo Report

0

He actualizado Model View y Controller:

 <script type='text/javascript' language='javascript'> $(document).ready(function(){ $.ajax({ url:"<?php echo base_url();?>digital/dashboard/dig_short_hodm_table", type: 'POST', dataType: 'JSON', success:function (data) { var result = data.result;' var row = ""; for(i=0; i < result.length; i++) { row += "<tr>"; row += "<td>"+result[i].t_name+"</td>"; row += "<td>"+result[i].director+"</td>"; row += "<td>"+result[i].duration+"</td>"; row += "<td>"+result[i].status+"</td>"; row += "</tr>"; } $('#hodm_table > tbody').html(row); } }); event.preventDefault(); }); </script>

Aquí está mi modelo

 public function get_hodm() { $query = $this->db->get("hodm"); return $query->result_array(); }

Aquí está mi controlador

 public function dig_short_hodm_table(){ $data['result']=$this->pojo->get_hodm(); echo json_encode($data); }
over 4 years ago · Santiago Trujillo 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!