Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!