dongsui0929 2019-02-19 04:20
浏览 63

使用ajax将字符串传递给opencart

I have an Opencart website, I am currently trying to use ajax at the frontend to pass data to php controller in the backend, but I am unable to get the value from the request in backend

here is the frontend ajax code:

$.ajax({    url: 'index.php?route=checkout/cart/addAll',
        type: 'post',
        data: 'product_list= test' ,
        dataType: 'json',

        success: function(json) {});

at the backend controller, I am trying to retrieve variable "product_list" but it is not working

$products = $this->request->post['product_list'];
$logger->write("products to add to cart is"+ strval($products));

the last statement keeps printing 0 to the log file any help with this ? what is wrong here?

I also tried

$products = json_decode($this->request->post['product_list'], true);

with same results

  • 写回答

2条回答 默认 最新

  • dqsp60748 2019-03-01 20:50
    关注

    Ok, fixed, Ajax was not the issue, it was accessing the variable from server side, so I used $_POST instead of $this->request->post and it is working fine

    评论

报告相同问题?