@McThinker

Где ошибка в коде?

<script>
  async function send() {
    let frm = new FormData(document.getElementById("form-search"));
    let response = await fetch('/vip/orders_find', {
      method: 'POST',
      body: frm
    });
    if (response.ok) {
      let json = await response.json();
      $('#csrf').val(json.csrf);
      let res = json.search;

      function statusOrders(orderstatusid) {
        switch (orderstatusid) {
          case '2':
            result = '<span class="inWork">В работе</span>';
            break;
          case '3':
            result = '<span class="executed">Исполнен</span>';
            break;
          case '4':
            result = '<span class="сanceled">Отменен клиентом</span>';
            break;
          case '5':
            result = '<span class="erroneous">Ошибочный</span>';
            break;
          case '6':
            result = '<span class="provided">Информация предоставлена</span>';
            break;
        }
        return result;
      }

      function statusPayments(paymentid) {
        switch (paymentid) {
          case '1':
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Списание с пластиковой карты"><i class="fas fa-credit-card"></i></span>';
            break;
          case '2':
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Клиент выкупит самостоятельно"><i class="fas fa-user-graduate"></i></span>';
            break;
          case '3':
            result = '<span class="no-payments" data-toggle="tooltip" data-placement="bottom" title="Без оплаты"><i class="fas fa-credit-card"></i></span>';
            break;
          case '4':
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Биплан"><i class="far fa-money-bill-alt"></i></span>';
            break;
          case '5':
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Приват 48</span>';
            break;
          case '6':
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Неопределена"><i class="fas fa-question"></i></span>';
            break;
          default:
            result = '<span data-toggle="tooltip" data-placement="bottom" title="Неопределена"><i class="fas fa-question"></i></span>';
            break;
        }
        return result;
      }

      $('#productsTable').show();
      $("#productsTable tbody").empty();
      res.forEach(function (item) {
        $("#productsTable tbody").append(
          '<tr class="my-orders">' +
          '<td class="text-center">' + '<div class="time-start">' + item.datestart + '</div>' + item.time + '</td>' +
          '<td class="fio">' + item.fio + '</td>' +
          '<td>' + item.type + '</td>' +
          '<td class="preview-order"><button class="btn btn-fab btn-fab-sm" data-toggle="tooltip" data-placement="top" ><i class="far fa-eye"></i><div class="ripple-container"></div></button><span class="str">' + item.servicename + '</span></td>' +
          '<td class="text-center id-orders">' + item.order_id + '</td>' +
          '<td class="text-center statusorder">' + statusOrders(item.orderstatusid) + '</td>' +
          '<td class="text-center statuspay">' + statusPayments(item.paymentid) + '</td>' +
          '<td class="str-fio">' + item.getname + '</td>' +
          '<td class="str-fio">' + item.doname + '</td>' +
          '</tr>'
        );

      });
      $('.preview-order button').hover(function () {
        let res = {};
        let l = this;
        console.log(this.parentNode);
        res['order_id'] = this.parentNode.nextSibling.textContent;
        console.log(res);
        $.ajax({
          type: "GET",
          url: '/vip/order_preview',
          dataType: 'json',
          async: false,
          data: res,
          success: function (data) {
            l.setAttribute('data-original-title', '' +
              '<div class="card-body-tooltip">\n' +
              '<div class="table-responsive">\n' +
              '<table class="table table-striped">\n' +
              '<thead>\n' +
              '<tr>\n' +
              '<th>Заказ: </th>\n' +
              '<th>Выполнение: </th>\n' +
              '</tr>\n' +
              '</thead>\n' +
              '<tbody>\n' +
              '<tr>\n' +
              '<td>' + data[0].servicedetail + '</td>' + '<td>' + data[0].servicecom + ' </td> \n' +
              '</tr>\n' +
              '</tbody>\n' +
              '</table>\n' +
              '</div>\n' +
              '</div>');
          }
        })
      });
      $(".preview-order button").tooltip({
        html: true,
      });
      $('.str').text(function (i, text) {
        if (text.length >= 40) {
          text = text.substring(0, 40);
          var lastIndex = text.lastIndexOf(" ");
          text = text.substring(0, lastIndex) + '... ';
        }
        $(this).text(text);
      });
      $(".str-fio").text(function (i, text) {

        if (text.length >= 20) {
          text = text.substring(0, 20);
          var lastIndex = text.lastIndexOf(" ");
          text = text.substring(0, lastIndex);
        }

        $(this).text(text);
      });
    } else {
      $("#productsTable tbody").append('<td class="err-search" colspan="5" >' + 'Уточните поиск' + '</td>');
    }
  }
</script>


Ошибка Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 2
  • Вопрос задан
  • 161 просмотр
Решения вопроса 1
ошибка не в этом коде, а в том, что ты фетчишь /vip/orders_find
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы