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.
|
2 answers
<?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(); |
echo $a? .... - Bookin$sum += $value->cart_amount * $value->pricethat 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