I have a variable
$b = 3; $c = 4;
$a = $b * $c; How do I pass the $ a variable in ajax for processing? I do not understand how. Can someone give an example of how variables are transmitted in ajax. No where I can not find.

  • echo $a ? .... - Bookin
  • This is where it is? How are variables passed to ajax data:? - Andrii
  • one
    but click on the ajax tag. Any examples you will not find? - Alexey Shimansky
  • Send or receive? - user208916
  • I have $sum += $value->cart_amount * $value->price that counts the amount of goods in the cart. When removing the goods by Ajax, the amount remains old until the reload. I understand that you need to transfer this variable to ajax data: process it and output the result. - Andrii

2 answers 2

 <?php ... $a = 'somedata'; echo json_encode(['a'=>$a]); ... //js code $.get('somescript.php', function(data){ data = JSON.parse(data); console.log(data.a); }); 
     var request = new XMLHttpRequest(); request.open('GET', '/'); request.onreadystatechange = function() { if (this.readyState != 4 || this.status != 200) { return; } var response = this.responseText; // <-- ОТВЕТ СЕРВЕРА } request.send();