fetch возвращает html вместо json
хочу перезаписать запрос $ajax который возвращает json на fetch, но fetch возвращает html. Подскажите какие настройки надо добавить в запросе или что я делаю не так
$.ajax({
url: "/project/data/",
type: "GET",
dataType: "json",
success: function(data, status) {
console.log(data);
}
})
fetch("/project/data/")
.then(res => res.json())
.then(res => {
console.log(res);
})
Ответы (1 шт):
Автор решения: MoloF
Использование
→ Ссылка
Использование Fetch
const fetchOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
fetch("/project/data/", fetchOptions)
.then(res => res.json())
.then(res => {
console.log(res);
});
