G
G
Goose_eich2021-08-12 17:28:32
AJAX
Goose_eich, 2021-08-12 17:28:32

How to pass cost value from cart js script?

Hello. There is a js code for the cart, where the total cost is deducted. I'm trying to pass it to post.php, where the payment form is already being processed. But the cost is not transferred, I'm trying to do it like this:

totalprice = (unitsprice + delcost).toFixed(2);
    $.ajax({
      url: "post.php",
      type: "POST",
      data: {"&amount" : JSON.stringify(totalprice)},      
    });

where totalprice is the total cost.
Then in the post.php file I try to get this value like this:
$data = "entityId=8ac9a4ca7a13eba8017a1dedeec37130" .
                json_decode($_POST["&amount"]) .
                "&currency=EUR" .
                "&paymentType=DB";

Initially, the php code looked like this:
$data = "entityId=8ac9a4ca7a13eba8017a1dedeec37130" .
               "&amount=92.00"
                "&currency=EUR" .
                "&paymentType=DB";

You need to replace the &amount value with mine from the totalprice variable in js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-08-12
@delphinpro

let totalprice = (unitsprice + delcost).toFixed(2);
$.ajax({
  url: "post.php",
  type: "POST",
  data: {
    amount: totalprice,
  },
});

$data = "entityId=8ac9a4ca7a13eba8017a1dedeec37130" .
        "&amount=" . $_POST["amount"] .
        "&currency=EUR" .
        "&paymentType=DB";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question