weixin_33676492 2017-08-25 18:26 采纳率: 0%
浏览 44

数组返回空值

I make a request in ajax at the click of the button passing the id of a product to a controller and it passes to the helper. In the helper, through this id of the product I add it to the cart, but that does not matter much on that issue. I create an array of data in this helper and return it, and the controller returns that array to the request. But when I give an alert in the array so I can see what it upsets me, it returns me a null value and I do not know why that happens.

Ajax request:

function addCartao(product_id){
                alert("entrou");
                alert(product_id);
                $j.ajax({
                  type: "POST",
                  url: "<?php echo Mage::getUrl('fol_carousel/ajax/teste') ?>",
                  data: {
                    product_id: product_id
                  },
                  dataType: 'json',
                  cache : false,
                  beforeSend: function () {
                    alert("beforeSend");
                  },
                  success: function (dados) {
                    alert("success");
                    alert(dados);
                  },
                  complete: function () {
                    alert("complete");
                  },
                  error: function (x,y,z) {
                    alert("error");
                    alert(x);
                    alert(y);
                    alert(z);
                  }
              });
            }

Controller:

$product_id = $this->getRequest()->getPost();
echo json_encode(Mage::helper('fol_carousel/cartao')->addCustom($product_id));

Array created in the helper:

$dados['product_name'] = "teste";
$dados['product_price'] = "2.99";
return $dados;

Every time the ajax request alert is executed, it returns me null.

  • 写回答

3条回答 默认 最新

  • 游.程 2017-08-25 19:18
    关注

    Open the developer tool and check what is there in the response of server call.

    Verify that your server code is receiving parameter that you posted and returning proper data.

    评论

报告相同问题?