在codeigniter中使用jquery ajax更新数据库

时间:2022-11-24 14:40:41

There are posts here already for this issue but I still don't get the database to update. Ajax sends me a 200 OK but as said no db update: (the $platform->id is not the issue, foreach is set). Thank you for help!

这里已经有关于这个问题的文章了,但是我仍然没有更新数据库。Ajax向我发送了一个200 OK,但如前所述没有db更新:($platform->id不是问题,foreach已经设置)。谢谢你的帮助!

Jquery

Jquery

$('#button_<?php echo $platform->id; ?>').click(function(event) {
    event.preventDefault();
    var platform_id = <?php echo $platform->id; ?>;
        $.ajax({
            type: "POST",
            url: "<?php echo site_url('home/select_job'); ?>",
            data: {id : platform_id},
            success: function(){ alert("success"); },
        });

Controller

控制器

$platform_id = $this->input->post('platform_id');
$user_id = $this->session->userdata('id');
$this->users_model->job_selection($user_id, $platform_id);

Model

模型

public function job_selection($user_id, $platform_id){
    $this->db->set('user_id', $user_id);
    $this->db->set('status', 2);
    $this->db->set('select_company', 1);
    $this->db->where('id', $platform_id);
    $this->db->update('companies');
}

1 个解决方案

#1


3  

You are making mistake to getting the platform_id it will be id because you set the name id into your ajax call try this into your controller

您错误地获取了platform_id,它将是id,因为您将名称id设置为ajax调用,请尝试将此设置为控制器

$platform_id = $_POST['id'];
$user_id = $this->session->userdata('id');
$this->users_model->job_selection($user_id, $platform_id);

Try this hope it will solve problem.

试试这个,希望它能解决问题。

#1


3  

You are making mistake to getting the platform_id it will be id because you set the name id into your ajax call try this into your controller

您错误地获取了platform_id,它将是id,因为您将名称id设置为ajax调用,请尝试将此设置为控制器

$platform_id = $_POST['id'];
$user_id = $this->session->userdata('id');
$this->users_model->job_selection($user_id, $platform_id);

Try this hope it will solve problem.

试试这个,希望它能解决问题。