Good morning everyone from Indonesia.
I have some web project with Codeigniter framework. I have some fieldset for insert some value input tag with radio button. I'm using some Wizard Function for every single fieldset. In the end of each Wizard, We have some button. We add some javaScript function on this button. In javaScript function, we add some Ajax function. Ajax function can sending some value from "view" to "controller". After that, on "controller" we save the data with "model" to database.
The question is, why I can't save the data to database with ajax function I have made before?
This is "view" (javascript and ajax)
function prosesFieldset1(){
var radios = document.getElementsByName('f3');
for (var r=0, length = radios.length; r < length; r++){
if(radios[r].checked){
var dataf3 = radios[r].value;
if (dataf3 == 1 || dataf3 == 2 ){
_('fieldset1').style.display = 'none';
_('fieldset2').style.display = 'block';
_('progressBar').value = 25;
}else{
_('fieldset1').style.display = 'none';
_('fieldset3').style.display = 'block';
_('progressBar').value = 25;
}
}
}
var f3 = dataf3;
$.ajax({
url : "<?php echo site_url('TracerStudy/masuk_data_ts');?>",
type : 'post',
data : {'f3' : f3, 'proses' : 1},
success : function(data){
console.log(data);
},
});
}
This is the "controller" for get data from Ajax on "view" to restore them in to new variable and save them to database (TracerStudy/masuk_data_ts)
public function masuk_data_ts(){
$f3 = $this->input->post('f3');
$proses = $this->input->post('proses');
if($proses == 1){
$id_alumni = $this->session->userdata('id_alumni');
$udah = $this->TracerStudy_model->get_data_ts($id_alumni);
if($udah = 1 ){
$data = array(
'id_alumni_fk' => $this->session->userdata('id_alumni'),
'f3' => $f3
);
// $proses = 0;
$this->TracerStudy_model->update_data_ts($data);
}
else{
$data = array(
'id_alumni_fk' => $this->session->userdata('id_alumni'),
'f3' => $f3,
'status' => $proses
);
// $proses = 0;
$this->TracerStudy_model->simpan_data_ts($data);
}
}
This is "model" to save data into database (TracerStudy_model/simpan_data_ts)
public function simpan_data_ts($data){
$this->db->insert("tracer_study", $data);
}
I have appreciate for any suggestion, and solution to this problem. Thank you everyone, I hope for all of you, have a nice day today.