skip to Main Content

I can’t update because it appears that this request has no response data available, but when I run it with print_r the data appears, and when I set the update data query builder, the error appears. please help me..

    var id = $('#id').val();
    var akses_lihat = $('#akses_lihat').val();

    $.ajax({
        url: '<?php echo base_url('User_Akses/update_akses') ?>',
        method: 'POST',
        dataType: 'JSON',
        data: {
            id: id,
            akses_lihat: akses_lihat
        },
        success: function(data) {
            
        }
    });



public function update_akses($id, $akses_lihat) {
    return $this->db->where('id', $id)->update('data_users_akses', array('akses_lihat' => $akses_lihat));
}

the hope is that my task will be completed quickly and found a good solution

2

Answers


  1. Change the model function like below. Ajax expects to return JSON. But your model return TRUE/FALSE

    public function update_akses($id, $akses_lihat) {
        $response["status"] = false;
        $updateStatus =  $this->db->where('id', $id)->update('data_users_akses', array('akses_lihat' => $akses_lihat));
    
        if($updateStatus){
            $response["status"] = true;
        }
        return json_encode($response);
    }
    
    Login or Signup to reply.
  2. That’s because you are not sending a valid json response from your controller. For that:

    public function update_akses($id, $akses_lihat) {
        $status = $this->db->where('id', $id)->update('data_users_akses', array('akses_lihat' => $akses_lihat));
    
        // send json response back to ajax request
        $this->output->set_content_type('application/json')->set_output(json_encode(array('status' => $status)));
    }
    

    See output class details here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search