使用ajax更新无法在数据表和codeigniter上运行 [英] Using ajax to update is not working on data-table and codeigniter

查看:52
本文介绍了使用ajax更新无法在数据表和codeigniter上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

您的更新调用参数被颠倒了。根据您的 update_book 模型函数,第一个参数是要更新的数据数组,第二个参数是where数组。但是这里 $ this-> user_model-> update_book(array('book_id'=> $ this-> input-> post('book_id')),$ data); 您首先要在哪里,然后是数据。



应为:

  $ this-> user_model-> update_book($ data,array('book_id'=> $ this-> input-> post('book_id')))); 


!My update is not working but I using the same code in its website. https://mbahcoding.com/tutorial/php/codeigniter/codeigniter-ajax-crud-modal-server-side-validation.html

My update chrome in the network preview

enter image description here.

sample website update chrome in the network preview

enter image description here.

Here is ajax update on network response. enter image description here

I try normal way to do it but always have an error.

controller......

 public function ajax_update()
{

    $data = array(
            'book_title' => $this->input->post('book_title'),
            'book_isbn' => $this->input->post('book_isbn'),
            'book_yop' => $this->input->post('book_yop'),
            'book_active' => $this->input->post('book_active'),
            'author_name' => $this->input->post('author_name'),
             'publisher_name' => $this->input->post('publisher_name'),
        );
  $this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data);
    echo json_encode(array("status" => TRUE));

}

model..........

public function update_book($data, $where)
{    

       $this->db->update('books',$data,$where);
         return $this->db->affected_rows();

}

If I print_r($data); blew is the result. I think my issue is data is not passed to the database.

解决方案

Your update call parameters are reversed. According to your update_book model function the first parameter is the array of data to update, and the second parameter is the where array. However here $this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data); you have your where first and data second.

It should be:

$this->user_model->update_book($data, array('book_id' => $this->input->post('book_id')));

这篇关于使用ajax更新无法在数据表和codeigniter上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆