I have got a script in JS and there is a function with the json response. I want to use the response (the value) and use in the php function (instead of hardcoding it with the number).
To be exact, I want to use the value *totalAmount * from the getTotal() function and use it in the $ParArray as "amount" in php (insetad of hardcoding).
How can I do this? Any hints will be helpfull! :)
<?php include 'includes/session.php'; ?>
<?php include 'includes/scripts.php'; ?>
<script>
var total = 0;
var city = $('#city').val();
$(function() {
(...)
function getTotal() {
$.ajax({
type: 'POST',
url: 'total.php',
dataType: 'json',
data: function(response) {
totalAmount = response;
}
});
}
</script>
<?php
$ParArray = array(
"amount" => "55",
"currency" => "USD",
"type" => "0",
);
(...)
?>