Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('.filter_link').on('click', async function(event) {
- let url = window.location.pathname;
- window.location.pathname = '/4gb-v/';
- event.preventDefault();
- const gallery_products_display_div = $('.product-list');
- let filter_category = await fetch(url).then(function(response){
- console.log('готово');
- }).catch(function(err){
- console.log('Fetch problem' + err.message);
- });
- // if (response.ok) { // если HTTP-статус в диапазоне 200-299
- // // получаем тело ответа (см. про этот метод ниже)
- // let json = await response.json();
- // } else {
- // alert("Ошибка HTTP: " + response.status);
- // };
- let csrfToken = getCookie('csrftoken');
- let data = {
- 'filter_category': filter_category,
- 'csrfmiddlewaretoken': csrfToken,
- };
- gallery_products_display_div.empty();
- $.ajax({
- type: "POST",
- data: data,
- url: url,
- success: function (response){
- //JSON.parse ожидает строку в параметре. Чтобы решить эту проблему, вам нужно привести в порядок свой JSON-объект.
- document.querySelector('.product-list').textContent = response;
- // let getData = JSON.parse(JSON.stringify(response));
- // console.log(getData);
- },
- error: function (response){
- alert('ошибочка вышла');
- }
- });
- });
- // функция для получения куки
- // let csrfToken = getCookie('csrftoken');
- function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie !== '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = cookies[i].trim();
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) === (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement