jQuery从PHP控制器发送值的问题$this->input->post('id', TRUE);.

Issues with jQuery sending value from PHP controller $this->input->post('id', TRUE);

本文关键字:TRUE input- post id this- 控制器 PHP 问题 jQuery      更新时间:2023-09-26

view.php

$(document).ready(function() { 
    $('.buttons > a').livequery("click",function(e){
        var parent  = $(this).parent();
        var getID   =  parent.attr('id').replace('button_','');
        var url = '<?php echo site_url('cart/price');?>';
        $.post(url+"?id="+getID, {}, function(response){
            $('#button_'+getID).html($(response).fadeIn('slow'));
        });
    }); 
});
<span class="buttons" id="button_5"><a class="btn-following" href="javascript: void(0)"></a></span>

控制器:

$gid = $this->input->post('id', TRUE);
$this->Product_model->following($gid);

型:

function following($gid){       
    mysql_query("INSERT INTO tf_followers (following_id) VALUES('".$gid."')");        
}

从这里我得到空值到数据库,这是通过jQuery传递值的正确方法。

如果要

将数据正确传递给$.post,请使用其 3 参数重载:

$.post(url, {id: getID}, function(response){
    $('#button_'+getID).html($(response).fadeIn('slow'));
});

如果你想用GET传递它(就像你一样),你不能在服务器上的POST变量集合中获取它。