@X0lera

Как мне получить name?

function GetText() {
      fetch('http://api.kai-zer.ru/dev/method/products.getAll', {mode: 'no-cors'})
      .then((response) => response.name())
      .then((date) => {
        console.log(date[0])
      })
      .catch((err) => console.log(err))
    }
  • Вопрос задан
  • 141 просмотр
Решения вопроса 2
profesor08
@profesor08 Куратор тега JavaScript
fetch("api.kai-zer.ru/dev/method/products.getAll")
.then(r => r.json())
.then(data => {
  console.log(data.response);
})
Ответ написан
Xuxicheta
@Xuxicheta
инженер
Как писали выше, сначала надо сделать .then(r => r.json()), чтобы распарсить JSON
Но это не поможет, потому что вы, во-первых, используете запрещенный в скоупе window {mode: 'no-cors'}
А во-вторых с сервера приходит некорректный JSON, там сначала хтмл разметка в тексте, видимо сервер вставляет это в случае cors-запроса.

<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: host in /srv/SaraFannTest/public/index.php on line <i>33</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0001</td><td bgcolor='#eeeeec' align='right'>356992</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='/srv/SaraFannTest/public/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: scheme in /srv/SaraFannTest/public/index.php on line <i>34</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0001</td><td bgcolor='#eeeeec' align='right'>356992</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='/srv/SaraFannTest/public/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>0</td></tr>
</table></font>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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