I would like store data from ajax call inside php variables.
I have a list of orders taken directly from DB. I need ,at the click of a specific order, an ajax call provide to get the informations of this specific order with the ID order. I made this, but i don't understand how can i get the return data and store them in php variables.
I have correctly the JSON with all data inside, but i can't get it.
I tried with store, with some functions that work correctly, the result of json inside variables but i get nothing and i don't understand why.
My principal file are two:
- table_orders.tpl.php Here i have the list of all orders stored in DB, and if i click on one of them, i can explode a second file (order_details.tpl.php) with all details reported inside with the AJAX call.
...some code....
<td class="product_list" data-id="<?= $ordine["id_order"] ?>">
<?PHP
$idCart = $ordine["id_cart"];
$idOrder = $ordine["id_order"];
$prodotti = $dataProducts->getListProducts($idCart);
$nbProducts = $dataProducts->getCountProducts($idCart);
foreach ($prodotti as $prodotto):
?>
<b><?= $prodotto["reference"] ?></b> <?= $prodotto["reference"] ? "|" : "" ?> <?= $prodotto["quantity"] ?><br>
<?= ucfirst(strtolower($prodotto["name"])) ?><br>
<?PHP endforeach ?>
</td>
...some code...
<script>
$(".product_list").on("click", function () {
$("#order_detail").css("display", "block");
var id_ordine = $(this).attr("data-id");
$.ajax({
type: 'GET',
dataType:"jsonp",
data:{"id_ordine":id_ordine},
async:false,
url: 'http://localhost/en-manager/views/components/orders/order_details.tpl.php',
success: function (data, status, xhr) {
console.log('data: ', data);
}
});
});
</script>
- order_details.tpl.php This is the file called by AJAX and where i will put all the information order inside. As we can see in the screenshot, the data are correctly showed in JSON but, when i try to stored them in a php variable, i have absolutely nothing (even the dump $_REQUEST didn't get the 'id_ordine')
if ($_GET['id_ordine'])
{
if ( $indirizzoConsegna= ['Consegna' => $addressData::getAddressDeliveryWithIdOrder($_GET['id_ordine']) ] )
{
echo(json_encode($indirizzoConsegna, JSON_PRETTY_PRINT));
};
if ($invoiceAddress = ['Fattura' => $addressData::getAddressInvoiceWithIdOrder($_GET['id_ordine'])])
{
echo(json_encode($invoiceAddress, JSON_PRETTY_PRINT));
};
if ($orderDetail = ['DettaglioOrdine' => $orderData->getOrderById($_GET['id_ordine'])])
{
echo(json_encode($orderDetail, JSON_PRETTY_PRINT));
};
}
?>
<div class="container" id="order_detail" style="display:none;" >
<div class="row">
<div class="col-2">
<button type="button" onclick="closeWindow()" id="close_order_detail" class="btn btn-danger">Chiudi</button>
</div>
<div class="col-10">
</div>
</div>
<div class="row">
<div class="col-8">
<div class="row">
<div class="col">
<?= var_dump($indirizzoConsegna)?>
<b>ORDINE</b> n° del <b>DATA</b>
</div>
</div>
...some code...