douhan5547 2019-03-07 11:53
浏览 66
已采纳

我尝试使用post方法将值从ajax传递给codeigniter控制器,但它返回void

I tried to store ajax value in codeigniter controller variable using post method I used $this->input->post method in the controller but the variable in the controller is not getting the ajax value, the variable is returning as null, help me to find a solution for this error Thanks in advance.

Here is the code:

View:

<button type="button" class="btn btn-info btn-md edit-pdt" data-pid="<?php echo $row->product_id;?>"><i class="fa fa-pencil"></i></button>

Controller:

public function displayprodt()
    {
        $pid= $this->input->get('pid');
        $data = array(
            'title' => "Edit Product",
            'result' => $this->ProductModel->displayprodt($pid)
        );
        $this->load->view('header',$data);
        $this->load->view('navbar');
        $this->load->view('sidebar');
        $this->load->view('editproduct',$data);
        $this->load->view('footer');
    }

JQuery:

$('.edit-pdt').click(function(){
        var base_url = $("#base_url").val();
        var pid = $(this).attr("data-pid");
        alert(pid);
        $.ajax({
           type: "GET",
           url: base_url+"index.php/Product/displayprodt",
           data: ({pid: pid}),
           success: function(response) {
             location.href = base_url+"index.php/product/displayprodt";
           }
        });
  });

Model:

public function displayprodt($pid){
        $this->db->select("*");
        $this->db->from("todaysdeal_products");
        $this->db->where("product_id",$pid);
        $query = $this->db->get();
        return $query->result();
    }
</div>
  • 写回答

3条回答 默认 最新

  • dtrgqjcd877528 2019-03-07 13:04
    关注

    problem is your page redirects whatever returned from first request. please try replacing location.href = base_url+"index.php/product/displayprodt"; with console.log(response); or alert(response);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179