[英]Issues with jQuery sending value from PHP controller $this->input->post('id', TRUE);
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變量集合中獲得它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.