agency-zhilfond
61 строка · 1.6 Кб
1const url = 'http://127.0.0.1:8000/api/basket/';2function delItemBasket(itemBasketId) {3const otherParam = {4headers: {5"content-type": "application/json; charset=UTF-8",6},7method: "DELETE",8};9fetch(url + itemBasketId, otherParam)10.then(11response => {12if (response.status === 200) {13location.href = '/basket';14return response.json();15}16}17);18}
19
20function payBasket(basketId) {21const basket = {22"id": basketId,23};24const otherParam = {25headers: {26"content-type": "application/json; charset=UTF-8",27},28body: JSON.stringify(basket),29method: "POST",30};31console.log(basketId);32fetch(url + 'payment', otherParam)33.then(34response => {35if (response.status === 200) {36location.href = '/order';37return response.json();38}39}40);41}
42function sendBacket(productId) {43let el = document.getElementById("validationCustom"+productId)44if(el.value == 0) return45const product = {46"id": productId,47"quantity": Number(el.value),48};49const otherParam = {50headers: {51"content-type": "application/json; charset=UTF-8",52},53body: JSON.stringify(product),54method: "POST",55};56
57fetch(url, otherParam)58.then(data => data.json())59.then(response => console.log(response))60.catch(error => console.log(error));61}
62