/
json_test.php
37 lines (30 loc) · 1.11 KB
/
json_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<button class="btn">Click me</button>
<button class="btn">Click me too</button>
<button class="btn">Me too</button>
<p id="jou"></p>
<script>
var btn = document.getElementsByClassName("btn");
for (var i = 0; i < btn.length; i++) {
btn[i].onclick = function() {
var jou = document.getElementById("jou");
var total = 0;
fetch('getCartTotal_ajax.php', {
method: 'POST', // Send as POST
headers: { // Tells headers to the server
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
total: total
}) // Sending JSON-data to server
}).then(function(response) {
// when then-promise has been succesful parse to json
return response.json();
}).then(function(myJson) {
// when then-promise has been succesful modal opens
console.log("myJson");
jou.innerHTML = myJson;
});
}
}
</script>