Category : fetch-api

I run the following fetch/http request directly from my script in the browser: const t0 = performance.now(); fetch("https://api.example/something", { method: ‘get’, headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ } }).then(res=>res.json()) .then(res => { const t1 = performance.now(); console.log(t1 – t0); }); The timer returns on average 240ms. After that I tried doing it using node: var https = ..

Read more

I have an Web Api And since I made all the settings according to the internet tutorial, but in JavaScript Fetch I still get the error I put the following code in the web config: <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> And i put the following code in the Global: protected void Application_BeginRequest(object ..

Read more

I’ve tried promise chaining, where my chained var is valid, and my fetch is working with manually key-in data, but I can’t get it work by putting the var, the return console log shown blank value {"code":"success","message":null,"data":[]} or {"code":"success","message":null,"data":[Array(0)]}. Any suggestions on what I did wrong in my code? function anExportFunction(){ fetch(an_API_URL_01,{ method: ‘GET’, }).then(function(response) ..

Read more

I was learning about promises in javascript I copied the following code in chrome console and tried to execute it. const urls = [ "https://jsonplaceholder.typicode.com/users", "https://jsonplaceholder.typicode.com/posts", "https://jsonplaceholder.typicode.com/albums" ] Promise.all(urls.map(url => { return fetch(url).then(resp => resp.json()); })).then(results =>{ console.log(results[0]); console.log(results[1]); console.log(results[2]); }).catch(() => console.log("error")); and it shows errror. but the same code executes perfectly in firefox. ..

Read more

I am a newbie in express/Node.js things. I tried to post a request containing the current user location(longitude and latitude using geolocation api). /public/index.html <!DOCTYPE > <html> <head> <meta charset="UTF-8" /> <title>Hey</title> </head> <body> <h1>Welcome</h1> <button id="submit" class="click-btn">Submit my Location</button> </div> <script src="main.js"></script> </body> </html> /public/main.js //navigating the user’s current location using geolocation web api ..

Read more

I have a javascript fetch API call made to a Django backend server const res = fetch(url, { credentials: ‘include’, method: ‘POST’, mode: ‘same-origin’, headers: { ‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’, ‘X-CSRFToken’: csrftoken }, body: JSON.stringify(requestBody), }) .then((response) => response.json()) .then((responseJson) => { return responseJson.movies; }) .catch((error) => { console.error(error); }); If I output the requestBody ..

Read more