我通过ajax向控制器发送id。但是它不起作用,而ajax函数给出了像表格这样的大数据作为回应。请查看代码并指导我错在哪里。
<li class="sendRequest">
<a href="javascript:void(0);" onclick="cart.add('<?php echo $product['product_id']; ?>');"> <i class="fa fa-shopping-cart"></i><!--<img src="images/cart-icon.png" alt="cart" />--></a>
<div>Add To Container</div>
<form id="formSend" method="post" >
<input type="hidden" value="<?php echo $product['product_id']; ?>" name="sendProductId" class="pID" />
</form>
</li>
$( ".sendRequest" ).each(function(index) {
$(this).on("click", function(){
var otherInput = $(this).find('.pID').val();
$.ajax({
type:"post",
url:"index.php?route=common/personaliseyourflowers",
data:otherInput,
success:function(response){
alert(response);
}
});
});
});
if(isset($this->request->get['sendProductId'])){
$cookie_value = $this->request->get['sendProductId'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30));
}
print_r($_COOKIE);
当我打印cookie的全局变量时,它也会给出空白数组。
答案 0 :(得分:3)
替换
data:otherInput,
与
data:{'sendProductId':otherInput},
答案 1 :(得分:2)
更正您的Ajax调用,如下所示。
$.ajax({
type:"post",
url:"index.php?route=common/personaliseyourflowers",
data:{'sendProductId':otherInput},
success:function(response){
alert(response);
}
});