1

i want to insert data using Ajax to databse. But I got 500 Internal Server Error. After I check I get Call to undefined method Hire_model::InserData(). Can anyone help me to correct my code. Any help is appreciated Thanks!

  $('#button-smt').click(function(){
    var form_data = $('#myform').serialize();
       $.ajax({
        url:"<?php echo base_url('Hire/submit_hire');?>",
        method:"POST",
        data:form_data,

        success:function(data){
      console.log(data);
            if (data.status) {
              alert('sukses!');

            }
          },
        error:function(){
            alert('error ... ');

            //console.log(data);
            $('#myModal').hide();
            $('.modal-fade').hide();
            $(".modal-backdrop").remove();
        }
    });
});

My Controller

public function submit_hire(){
$total = $this->input->post('total');
$workdate = $this->input->post('workdate');
$data = array(
  'NumberOfPlacement' => $total,
  'ExpectedWorkStartDate' => $workdate
  );
$res = $this->hire_model->InserData('dbo.RequisitionTable' , $data);
if ($res) {
  echo json_encode(array('status'=>true));
}else
echo json_encode(array('status'=>false));
}

My Model

public function InsertData($tabelName, $data){
$res = $this->db->insert($tabelName, $data);
return $res;
 }
kitcat
  • 157
  • 1
  • 17

2 Answers2

0

Problem is in method name: (spelling mistake) $res = $this->hire_model->InserData('dbo.RequisitionTable' , $data);

It should be $this->hire_model->InsertData('dbo.RequisitionTable' , $data);

Reena
  • 1
0

Finally I found the mistake. Its the naming of the method in model. I changed InserData to Insert_data and it works now

kitcat
  • 157
  • 1
  • 17