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.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭