why doesn’t my ajax execute? I have checked the controller and the model and they were fine.
The problem is the main ajax which is :
function updateTable() {
var count = document.getElementsByName('chk[]').length;
var academic = document.getElementById('cb_AcademicYear').value;
var acyear = academic.substr(0,4);
var sem = "SE00"+academic.substr(5);
var yearlevel = document.getElementById('cb_Yearlevel').value;
var acstart = "";
var acend = "";
var atstart = "";
var atend = "";
var status = "";
var successCount =0;
var ele = "";
var data = "";
for (i=0;i<count;i++)
{
if(document.getElementById('chk_'+i).checked)
{
ele = i+"[]";
acstart = document.getElementById('acstart_'+i).value;
acend = document.getElementById('acend_'+i).value;
atstart = document.getElementById('atstart_'+i).value;
atend = document.getElementById('atend_'+i).value;
status = document.getElementById('cmb_'+i).value;
var postData = {
'acyear' : acyear,
'sem' : sem,
'yearlevel' : yearlevel,
'acstart' : acstart,
'acend' : acend,
'atstart' : atstart,
'atend' : atend,
'status' : status
};
$.ajax({
url: '<?php echo base_url()?>academicCalendar_entry/update',
data: postData ,
type: 'POST',
success: function (data){
successCount++;
}
});
}
}
alert("Successfully inserted ("+successCount+") data(s) including: "+count+ele+acstart+acend+atstart+atend+status+"\n"+academic+acyear+sem+yearlevel+"\n\nand this is the link for the jquery : <?php echo base_url()?>academicCalendar_entry/update/");
}
I put the postdata as an array, which suppose to be fine. But I didn’t put it as a json datatype. Do I have to put it as a json datatype? In the error console, I see no error message but it still didn’t execute to the database.
can anyone solve this??
Edited on 12 Dec 2012 :
this is my update() function in my controller :
function update()
{
$academic_year = $_POST['acyear']; //trim($this->input->post('acyear'));
$semester = $_POST['sem']; //trim($this->input->post('sem'));
$yearlevel = $_POST['yearlevel']; //trim($this->input->post('yearlevel'));
$acstart = $_POST['acstart']; //trim($this->input->post('acstart'));
$acend = $_POST['acend']; //trim($this->input->post('acend'));
$atstart = $_POST['atstart']; //trim($this->input->post('atstart'));
$atend = $_POST['atend']; //trim($this->input->post('atend'));
$status = $_POST['status']; //trim($this->input->post('status'));
$auditname = "Admin";
$auditactivity = "U";
$audittime = date("Y-m-d");
$this->load->model('calendar_Model','cm');
$this->cm->updateAcademicEntry($academic_year,$semester,$yearlevel,$acstart,$acend,$atstart,$atend,$status,$auditname, $auditactivity, $audittime);
return true;
}
I have tried using the $this->input->post, with trim, and with $_POST(), but none of them solve it.
And this is where I put the updateTable() func :
<input type="submit" name="btn_save" id="btn_save" value="Save" onclick="updateTable()"/>
This is my updateAcademicEntry() func in Model :
function updateAcademicEntry($academic_year,$semester,$yearlevel,$acstart,$acend,$atstart,$atend,$status,$auditname, $auditactivity, $audittime)
{
$data = array(
'Tahun_Akademik'=>$academic_year,
'Tanggal_Mulai_Akademik'=>$acstart,
'Tanggal_Akhir_Akademik'=>$acend,
'Tanggal_Mulai_Kehadiran'=>$atstart,
'Tanggal_Akhir_Kehadiran'=>$atend,
'Status'=>$status,
'NamaAudit'=>$auditname,
'AktivitasAudit'=>$auditactivity,
'TanggalAudit'=>$audittime,
'ID_Semester'=>$semester,
'ID_Level_Year'=>$yearLevel
);
$this->db
->where('Tahun_Akademik',$academic_year)
->where('ID_Level_Year',$yearLevel)
->where('ID_Semester',$semester)
->update('trkalenderakademik',$data);
}
There are 2 possible problems:
There is an error in your controller. In which case you have to change it.
You mean to add the alert in the callback. Currently the alert runs if the function works or not.
Also since the ajax runs async to the alert the alert will not have update value of
successcount