想要在PHP代码点火器中将数据传递到下一页

时间:2018-03-22 16:37:55

标签: php jquery ajax codeigniter

$(".content-wrapper").on("click",".modalButton", function(e) {  
    $.ajax({
        url : "<?php echo base_url()."stock_details/edit";?>",
        method: "post", 
        data : {
        id: $(this).attr("data-src")
        }
        }).done(function(data) {
        $(location).attr('href', '<?php echo base_url()."stock_details/edit";?>').html(data);

    })
});

此代码用于编辑表数据 我只是传递当前行id并检索数据然后我想将数据传递到编辑页面我遇到了问题

1 个答案:

答案 0 :(得分:0)

As you do only request the edit page with the $(location).attr('href',URL) call, you do not post any data. I would recommend you to send the ID as a GET parameter instead, change the line to:

$(location).attr('href', '<?php echo base_url(); ?>stock_details/edit?id='+$(this).attr("data-src"));

OR, even more CI-like, send it to the controller as a parameter:

$(location).attr('href', '<?php echo base_url(); ?>stock_details/edit/'+$(this).attr("data-src"));

Then in the controller/model for the edit page add possibility to use both POST and GET the id value.