1

次の Ajax 呼び出しがあります。

    $.ajax({
    type: 'POST',
    url: myBaseUrl + 'Products/addItemToBasket',
    dataType: 'json',
    data: {
        id: window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1),
        amount: amount
    },
    success: function (data) {
        alert(data);
        var dat = JSON.parse(data);
       }
    }
});

これで、php で次のメソッドが呼び出されます。

    public function addItemToBasket()
{
    if ($this->request->is('post')) {
        //todo delete efter at have insat fancybox med valg af antal styk. (sendes via ajax).
            $shopping = null;
            $item = $this->Product->find('first',array('conditions' => array('Product.id' =>$this->request->data['id'])));
        if(isset($_SESSION['basket'])){
            $shopping =  $_SESSION['basket'];
        }else{
            $shopping = array();
        }
        array_push($shopping,$item);
        $_SESSION['basket'] = $shopping;
        echo json_encode($_SESSION['basket']);
    }
}

デバッグしようとすると、すべてが機能し (php 関数に入ります)、$_SESSION変数が更新されます。

しかし、成功関数を実行することはなく、データを警告することもありません。

私は何を間違っていますか?

4

1 に答える 1