繁体   English   中英

Ajax无法使用php正确给出响应

[英]Ajax does not giving response properly using php

我通过Ajax将ID发布到控制器。 但是它不起作用,并且ajax函数可以响应像大表这样的大数据。 请查看代码,并在错误的地方指导我。

HTML

  <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>

JS

$( ".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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM