Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserverprogrammering/projekt/snake_oil_seller/js/

style.js
use_cart.js

use_cart.js

33 lines ASCII Windows (CRLF)
function add_to_cart(product_id) {
  fetch("../php/add_to_cart.php", {
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    body: "product_id=" + product_id
  })
  .then(response => response.text())
  .then(data => {
    console.log(data);
  });
}

function clear_cart() {
  fetch("../php/shopping_cart.php", {
    method: "POST"
  })
  .then(response => response.text())
  .then(data => {
  location.reload();
  });
}

function buy_cart() {
  fetch("../php/buy_cart.php", {
    method: "POST"
  })
  .then(response => response.text())
  .then(data => {
  location.reload();
  });
}