doushang9172 2017-02-23 12:56
浏览 50
已采纳

ajax复选框没有将我的数据传递给codeigniter中的控制器

I'm trying to update my database data using checked box with ajax. the checkbox is running when I clicked it alert the success msg. but not passing the data to my controller. I don't know where to find my mistake here. I'm trying to figure out how to check if the data is pass to my controller.

Anyone can help me?

view

$checked = FALSE;
if($result->consignment == 1) { $checked = TRUE; }
    $data = array(
        'value'   => $result->id, 
        'onClick' => 'incoming_CheckboxState();',
        'class'   => 'incoming',
        'checked' => $checked
    );
echo form_checkbox($data);?> Incoming

ajax

function incoming_CheckboxState() {
  if ($('.incoming').is(':checked')) {

    var id = $('.incoming').val();
    var yes = 1;                
    $.ajax({
        type: "POST",
        url: "<?=based_url(); ?>user_accounts/update_permission",
        data: { user_id : id, status : yes },
        success: function(msg) {
            alert("Activated");
        }
    });
  } 
}

controller

public function update_permission(){
    $data = array(
       'id' => $this->input->post('user_id'),
        'status' => $this->input->post('status')
    );
    $this->user_accounts_model->incoming($data);
}

model

public function incoming($data){
    $this->db->set('consignment', $data['status'])
             ->where('id', $data['id'])
             ->update('users');
}
  • 写回答

2条回答 默认 最新

  • dougu1045 2017-02-23 13:33
    关注

    Do these

    1. Change AJAX URL

      url: "<?=base_url()?>user_accounts/update_permission"
      
    2. Set your base_url.(application/config/config.php)

      $config['base_url'] = 'http://stackoverflow.com/';
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制