【问题标题】:Using ajax to update is not working on data-table and codeigniter使用 ajax 更新不适用于数据表和 codeigniter
【发布时间】:2019-10-31 11:37:45
【问题描述】:

!我的更新不起作用,但我在其网站上使用了相同的代码。 https://mbahcoding.com/tutorial/php/codeigniter/codeigniter-ajax-crud-modal-server-side-validation.html

我在网络预览中的更新 chrome

enter image description here.

网络预览中的示例网站更新 chrome

enter image description here.

这里是关于网络响应的 ajax 更新。 enter image description here

我尝试了正常的方法,但总是出错。

控制器……

 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));

}

型号…………

public function update_book($data, $where)
{    

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

}

如果我 print_r($data);自爆就是结果。我认为我的问题是数据没有传递到数据库。

【问题讨论】:

  • 请告诉我们您收到的错误信息。此外,识别错误的行会有所帮助
  • 更新散文,使用$this->db->set($data_array)
  • 没有错误信息,当我点击更新时没有任何变化。
  • 在开发工具上,在网络预览中选择ajax_update请求然后选择response选项卡,并在此处报告结果
  • 在 ajax_update 中只有雕像:true。

标签: php ajax codeigniter datatable


【解决方案1】:

您的更新调用参数是相反的。根据您的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')));

【讨论】:

  • 嗨,Alex,我试过了,但还是一样,没有变化,也没有错误消息。
  • 在 database.php 中打开 db_debug 并提交您的表单。打开谷歌开发工具控制台。检查控制台错误。如果没有,则找到对控制器函数的请求并预览响应以查看发生了什么错误。
  • 我检查了我发现的唯一问题是 draw aways 0 并且我更新了图片。
  • 那是数据表,你需要看ajax_update一个......你有问题的那个......
  • 好吧,其他一切都检查出来了。您的更新查询构建器的语法、传递的帖子变量等。甚至您的 print_r 也显示您正在获取从表单发送的数据。如果您是 100% 更新到 $this->user_model->update_book($data, array('book_id' => $this->input->post('book_id'))); 的人,那么它不会更新的唯一原因是发生数据库错误。你打开 db_debug 了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-01
  • 2013-01-27
  • 2016-04-07
  • 2015-02-09
  • 2021-04-02
  • 2018-02-28
  • 1970-01-01
相关资源
最近更新 更多