javascript - read selected variable and then send back from table to controller -


i having table data database called through codeigniter controller.what want read selected value within table send controller , use values retrieve new records db , load them on again page.

my controller:

<?php   if (!defined('basepath'))     exit('no direct script access allowed');       class dashboard1 extends ci_controller {        public function __construct() {         parent::__construct();         $this->load->library('form_validation');          $this->load->model('dash_match_model');          $this->session->keep_flashdata('supplier_id');         $this->load->helper('url');           $this->load->database();     }      public function index() {        $arr['page']='dash1';        $arr['present_all_suppliers'] = $this->dash_match_model->dash_present_all_suppliers();          $arr['suppliercompany'] = "";              $this->load->view('clients/cldashboard',$arr);      }      public function select_supplier() {          $suppliercompany = $this->input ->post('suppliercompany');         $arr['present_all_suppliers'] = $this->dash_match_model->dash_present_all_suppliers();         $arr['suppliercompany'] = $suppliercompany;          $supplier_selected = $this->user_model->return_selected_supplier($suppliercompany);             foreach($supplier_selected->result() $row)             {                 $this->session->set_flashdata('supplier_id', $row->supplier_id);               }          $this->load->view('unspscsegment',$arr);     } } 

specific lines of table of view file:

<table id="suppliertable" class="table table-striped table-bordered bootstrap-datatable datatable">     <thead>         <tr>             <th>supplier</th>             <th>open range</th>             <th>fill content</th>             <th>total match</th>         </tr>     </thead>        <tbody>          <?php foreach ($present_all_suppliers $v): ?>             <tr>                  <td onclick="window.location = 'http://example.com'" class="center" style="color:#0c595b;"> <?php echo $v->suppliercompany; ?> </td>                 <td class="center"></td>                 <td class="center"></td>                 <td class="center"></td>             </tr>         <?php endforeach; ?>       </tbody> </table> 

how can javascript when select supplier (value) selected value , sent controller? should modify controller in order send value model , collect , reload them in view?

you can use jquery.ajax()

implemented in code:

script:

<script>     $(".supplier_edit").click(function(){         var supplier_company = $(this).find('input').val()         $.ajax({             type: 'post',             url: 'http://example.com/'+'dashboard1/select_supplier',             data: {suppliercompany: supplier_company},             success: function(result) {                 $("#content").html(result)             }         })         return false     }) </script> 

html:

<tbody>     <?php foreach ($present_all_suppliers $v): ?>         <tr>             <td class="supplier_edit" style="color:#0c595b;"><input type="hidden" value="<?php echo $v->suppliercompany; ?>" ></td>             <td class="center"></td>             <td class="center"></td>             <td class="center"></td>         </tr>     <?php endforeach; ?> </tbody>  <div id="content">content controller</div> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -