Благодаря ответу и предложениям Кеннета я понял, что мне нужно делать. Есть дополнительный слой, потому что это сайт ExpressionEngine, но по сути мне нужно было сообщить функции, что переменная поступила из сообщения, вот так:
Код: Выделить всё
$newItems = $this->EE->input->post('newItems');
$newItems = json_decode($newItems, true);
Выполнив приведенное ниже предложение Кеннета, я смог получить javascript, чтобы распознать, что я передал r.newItems. Но моя функция php не распознает, что она получает массив. Вот какая ошибка, которую я получаю:
Код: Выделить всё
PHP Warning: Missing argument 1 for Order::addReorderToCart()
Код: Выделить всё
public function addReorderToCart($newItems) {
error_log("newitems");
error_log(print_r($newItems,1)); // this is not printing anything
$_SESSION['order']['items'] = array_merge($_SESSION['order']['items'], $newItems);
$this->EE->app->addToCart();
$rtnArray['success'] = true;
}
У меня есть следующий код javascript/jquery, который запускается в результате другого вызова ajax:
Код: Выделить всё
function ohReorderAjaxReturn(data) {
console.log("ajax return");
console.dir(data);
var r = eval(data);
console.log("r");
console.dir(r);
if(data.unavailableItems instanceof Array && data.unavailableItems.length > 0) {
// there are unavailable items; ask if they want to go ahead
Modal({
title: r.errTitle,
text: r.errMsg, // need to update this to contain correct text including store address and unavailableItems
yellow_button: {
btn_text: "It's OK, continue",
action: function(r){
console.log("r inside function");
console.log(r);
// need ajax call to addReorderToCart
$.post('/site/ajax/order/addReorderToCart', {'newItems': r.newItems},
function(data) {
var ret = eval(data);
if( ret.success == 1 ) {
document.location = '/site/order_summary';
}
else {
alert("error");
}
});
}
},
black_button: {
btn_text: "Cancel"
}
});
}
else {
console.log("not an array");
// there are no unavailable items; add to cart and continue on
}
}
[img]https://i .sstatic.net/KuhEs.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/166 ... p-can-read
Мобильная версия