Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
JavaScript - fetching data from webserver only getting 'redirected' response from cors

So I managed to make my first API accessible locally. However when I try to fetch data like I would normally (URL to phpscript to get data from db), I only get a Response telling me that I was successfully redirected. In which way should I change my fetch function to make this work?

script.js

async function getTop10() {
    let url = 'http://192.168.2.131:81/stern';
    try {
        let res = await fetch(url);
        console.log(res);
        return await res.json();
    } catch (error) {
        console.log(error);
    }
}
getTop10();

Response

Response {type: 'cors', url: 'http://192.168.2.131:81/stern/', redirected: true, status: 200, ok: true, …}
body: (...)
bodyUsed: true
headers: Headers {}
ok: true
redirected: true
status: 200
statusText: "OK"
type: "cors"
url: "http://192.168.2.131:81/stern/"
[[Prototype]]: Response

Sample dataset from the url

[
    [
        "Nach",
        20
    ],
    [
        "In",
        16
    ],
    [
        "Sie",
        15
    ],
    [
        "Die",
        14
    ],
    [
        "So",
        10
    ],
    [
        "Putin",
        10
    ],
    [
        "Das",
        9
    ],
    [
        "Ukraine",
        9
    ],
    [
        "Deutschland",
        9
    ],
    [
        "Der",
        8
    ]
]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const getTop10 = async () => {
      let url = 'http://192.168.2.131:81/stern';
      try {
            const res = await fetch(URL);
            const data = await res.json();
            console.log(data);
      } catch (error) {
            console.log(error);
      }
}
getTop10();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda