ajax使用bootstrap模式返回数据无法获取模态内的参数

时间:2015-12-29 04:49:24

标签: php jquery ajax twitter-bootstrap codeigniter

我想使用来自ajax返回数据的PHP Codeigniter提交数据参数,但是当我提交表单时,我无法获取此参数。

HTML:

 <a href="#myModalBiaya" class="trash" role="button" data-toggle="modal">
                <button class="btn btn-success btn-sm" name="pdetailbiaya" value="Detail Biaya" >Detail Biaya</button>
               </a>

JS:

$('#myModalBiaya').on('shown.bs.modal', function(e) {
           po_id = $('#po_id').val();
           $.ajax({
        type: 'post',
        url: '<?php echo base_url();?>admin/po_trans_receive_po/getBiaya',
        data:'po_id='+po_id,
                  success: function(data){
                      $("#myModalBiaya .tdata").html(data);
        }
      });
  });

模态:

...
<div class="modal-body">
<div class="panel panel-default" >
                   <div class="panel-heading">
                     <div class="form-horizontal tdata" >
                    <div class="form-group" >
<label class='col-md-3 control-label' for='menu_name'>Biaya PPN </label>  
                         <div class='col-md-8'> 
                           <input type="text" name="po_biaya_ppn" id="po_biaya_ppn" readonly onkeyup="getTotalBiaya()"class="form-control text-right" value="0">
                         </div>
                        </div>
...

PHP:

 function getBiaya()
 {
     $po_id = $this->input->post('po_id');
     $resultPO = $this->md_po_trans_po->getID($po_id);

if ($resultPO) {
             $resultotal = $resultPO->po_biaya_ppn+$resultPO->po_ongkos_angkut+$resultPO->po_biaya_asuransi+$resultPO->po_biaya_materai;

  echo '      <div class="form-group" >                                                                                                                                                      ';
    echo '              <label class="col-md-3 control-label">Biaya PPN </label>                                                                                                                 ';
    echo '               <div class="col-md-8">                                                                                                                                                  ';
    echo '                 <input type="text" name="po_biaya_ppn" id="po_biaya_ppn" readonly onkeyup="getTotalBiaya()" class="form-control text-right" value="'.$resultPO->po_biaya_ppn.'">       ';
    echo '               </div>                                                                                                                                                                  ';
    echo '                  </div>     ';
}

除非输入参数po_biaya_ppn在我提交此表单时为空,否则一切正常。当我print_r($this->input->post('po_biaya_ppn'));die();时,它会返回空白。

此致 谢谢

1 个答案:

答案 0 :(得分:-1)

替换

 data:'po_id='+po_id,

var form_data = {
    po_id : po_id,
};
data:form_data,