jquery - Ajax get column table value to become a variable in javascript -


i want column table value become variable in javascript complete formula: 10 * vhasil_m * 32.03* 1000 / 5.

i have query this:

select round(avg(cast(t_dtl.hasil_m decimal(6,4))),4) hasil_m t_hdr join  t_dtl on t_hdr.headerid = t_dtl.headerid id_solvent ='naoh' , status='ok' , concentrate='0.0100' , date_start <='2016-05-01' , date_finish >='2016-05-01' 

the query result like:

| hasil_m     | | ----------- | | 0.0100      | 

i want above column value become variable formula, vhasil_m.

to run query, i've created model:

function getdata_naoh($datetest){     $result = $this->db1->query("select round(avg(cast(t_dtl.hasil_m decimal(6,4))),4) hasil_m t_hdr join  t_dtl on t_hdr.headerid = t_dtl.headerid id_solvent ='naoh' , status='ok' , concentrate='0.0100' , date_start <='$datetest' , date_finish >='$datetest'");     if($result->num_rows()>0){         return $result->result_array();     }else{         return array();     } } 

and controller executed it:

function get_naoh(){     $date_analysis = trim($this->input->post('date_analysis'));     $datetest = trim($this->input->post('date_analysis'));     $datetest = substr($datetest,6,4).'-'.substr($datetest,3,2).'-'.substr($datetest,0,2);      $dtnaoh = $this->m_tambahan->getdata_naoh($datetest);      foreach($dtnaoh $row){         $data1 .= $row[hasil_m];     }      $data =  $data1;     echo $data; } 

then create ajax this:

<script type="text/javascript"> $(document).ready(function(){       $(document).on('change','.no_picno', function() {         var = $(this);         var dt_no = that.val();         console.log(that.next());         var col_date_analysis =  that.parent().prev().find('.date_analysis');         var date_analysis = col_date_analysis.val();          $.ajax({                   type :"post",                   url : "<?php echo base_url();?>index.php/additionals/file/c_utils/get_naoh",                   data : { date_analysis: date_analysis, no_picno: dt_no },                   success: function(data){                       // code here                   }         });     }); }); </script> 

the ajax work without error, create javascript run formula:

<script type="text/javascript">     function gettotal() {         var obj = document.getelementsbytagname('input');            for(var i=0; < obj.length; i++) {           if (obj[i].name == "sulfur_vnaoh[]") {                var dt_sulfur_vnaoh = obj[i].value;           };           if (obj[i].name == "sulfur_ws[]") {                var dt_sulfur_ws = obj[i].value           };           if (obj[i].name == "sulfur_hasil[]") {             if ((dt_sulfur_ws != '')&&(dt_sulfur_vnaoh != '')) {                 var totalsulfur = 10*vhasil_m*32.03*1000/5;               obj[i].value = totalsulfur;             } else {                 obj[i].value = '';             };           };         }     }; </script> 

how declare or initializing ajax result variable in javascript complete formula ?

thanks.

in ajax code need create global variable store data:

<script type="text/javascript"> $(document).ready(function(){       $(document).on('change','.no_picno', function() {         var = $(this);         var dt_no = that.val();         console.log(that.next());         var col_date_analysis =  that.parent().prev().find('.date_analysis');         var date_analysis = col_date_analysis.val();          $.ajax({                   type :"post",                   url : "<?php echo base_url();?>index.php/additionals/file/c_utils/get_naoh",                   data : { date_analysis: date_analysis, no_picno: dt_no },                   success: function(data){                       window.data=data;                   }         });     }); }); </script> 

and after ajax call, fire gettotal() function, instead of using vhasil_m in formula use window.data:

<script type="text/javascript">     function gettotal() {         var obj = document.getelementsbytagname('input');            for(var i=0; < obj.length; i++) {           if (obj[i].name == "sulfur_vnaoh[]") {                var dt_sulfur_vnaoh = obj[i].value;           };           if (obj[i].name == "sulfur_ws[]") {                var dt_sulfur_ws = obj[i].value           };           if (obj[i].name == "sulfur_hasil[]") {             if ((dt_sulfur_ws != '')&&(dt_sulfur_vnaoh != '')) {                 var totalsulfur = 10*window.data*32.03*1000/5;               obj[i].value = totalsulfur;             } else {                 obj[i].value = '';             };           };         }     }; </script> 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -