简体   繁体   中英

Ajax does not giving response properly using php

I'm posting id through ajax to controller. But it does not working, and ajax function giving big data something like table in response. Please view the code and guide me where i'm wrong.

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);
                        }
                    });
                });
            });

Php Code

if(isset($this->request->get['sendProductId'])){
        $cookie_value = $this->request->get['sendProductId'];
        setcookie($cookie_name, $cookie_value, time() + (86400 * 30));

        }

        print_r($_COOKIE);

Also when i print the global variable of cookie it also giving blank array.

replace

data:otherInput,

with

data:{'sendProductId':otherInput},

correct your Ajax call as below.

   $.ajax({
                    type:"post",
                    url:"index.php?route=common/personaliseyourflowers",
                    data:{'sendProductId':otherInput},
                    success:function(response){
                        alert(response);
                    }
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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