Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda