agency-zhilfond

Форк
0
61 строка · 1.6 Кб
1
const url = 'http://127.0.0.1:8000/api/basket/';
2
function delItemBasket(itemBasketId) {
3
    const otherParam = {
4
        headers: {
5
            "content-type": "application/json; charset=UTF-8",
6
        },
7
        method: "DELETE",
8
    };
9
    fetch(url + itemBasketId, otherParam)
10
        .then(
11
            response => {
12
                if (response.status === 200) {
13
                    location.href = '/basket';
14
                    return response.json();
15
                }
16
            }
17
        );
18
}
19

20
function payBasket(basketId) {
21
    const basket = {
22
        "id": basketId,
23
    };
24
    const otherParam = {
25
        headers: {
26
            "content-type": "application/json; charset=UTF-8",
27
        },
28
        body: JSON.stringify(basket),
29
        method: "POST",
30
    };
31
    console.log(basketId);
32
    fetch(url + 'payment', otherParam)
33
        .then(
34
        response => {
35
            if (response.status === 200) {
36
                location.href = '/order';
37
                return response.json();
38
            }
39
        }
40
    );
41
}
42
function sendBacket(productId) {
43
    let el = document.getElementById("validationCustom"+productId)
44
    if(el.value == 0) return
45
    const product = {
46
        "id": productId,
47
        "quantity": Number(el.value),
48
    };
49
    const otherParam = {
50
        headers: {
51
            "content-type": "application/json; charset=UTF-8",
52
        },
53
        body: JSON.stringify(product),
54
        method: "POST",
55
    };
56

57
    fetch(url, otherParam)
58
        .then(data => data.json())
59
        .then(response => console.log(response))
60
        .catch(error => console.log(error));
61
}
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.