[英]Ajax does not giving response properly using php
我通过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的全局变量时,它也会给出空白数组。
更换
data:otherInput,
同
data:{'sendProductId':otherInput},
如下更正您的Ajax调用。
$.ajax({
type:"post",
url:"index.php?route=common/personaliseyourflowers",
data:{'sendProductId':otherInput},
success:function(response){
alert(response);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.