6,223 questions
-1
votes
1
answer
35
views
Failed to fetch when GETting json file from backend using Jwt Token
I am using a spring boot as backend and react frontend to create a website and I am encountering an error when fetching a user profile using browser from the backend.After login i managed to generate ...
-1
votes
0
answers
38
views
how to fix in app purchase error while requesting purchase it gives produc id undefind
when i fetch subscription from google play console it fetch the datas successfully. but the purchase does not work. it has some error
SubscriptionCard.js:99 Purchase error:
{code: 'item-unavailable', ...
-1
votes
0
answers
76
views
get the data from the server with fetch API [closed]
i get the data from the server with fetch API it contains html, when i click on load more posts button it should load the html at the bottom of the page we got from the server, but it also loads the ...
-3
votes
1
answer
103
views
how do I get html page with fetch for reload part of the page?
I am getting data from the server. The view must renders an html page without reloading the entire page، but this renders whole page including the header of current page, this is a problem, each time ...
-2
votes
0
answers
63
views
Why doesn't my .NET website support HTTP/3 in Chrome/Firefox? [closed]
I have a .NET website running on an internal IIS10/Windows Server 2022 machine. It has an internal SSL cert authorised by our domain. It works with HTTP/1.1 and HTTP/2.
It's configured to pass an alt-...
1
vote
2
answers
77
views
Why is my fetch POST request returning 415 Unsupported Media Type?
I’m trying to send a JSON payload to my backend API using fetch in React, but the server keeps returning:
415 Unsupported Media Type
Here is the code I'm using:
const sendData = async () => {
...
1373
votes
34
answers
4.3m
views
No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API
I'm trying to fetch some data from the REST API of HP Alm. It works pretty well with a small curl script—I get my data.
Now doing that with JavaScript, fetch and ES6 (more or less) seems to be a ...
0
votes
1
answer
122
views
Why does CORS apply to local files? And is there a way to just disable it? [duplicate]
I have been working on a personal project for a while now and during a testing phase for a database, it began reporting that CORS was preventing the file from being fetched, and stopped my testing in ...
0
votes
1
answer
92
views
javascript fetch and redirect through flask view not working as expected
In the html intro to a web app for a scientific study, data is collected through forms.
I added a javascript function that submits the data via the fetch API:
fetch('/prepare/', {
"method":...
0
votes
0
answers
86
views
What’s the correct way to fetch this API from the client side without hitting CORS errors? [duplicate]
I’m trying to call an external API from my JavaScript code using the fetch() method. It works perfectly on my local environment, but when I upload the same code to my website, I get a CORS error like ...
1148
votes
19
answers
2.0m
views
Fetch: POST JSON data
I'm trying to POST a JSON object using fetch.
From what I can understand, I need to attach a stringified object to the body of the request, e.g.:
fetch("/echo/json/",
{
headers: {
'...
1
vote
1
answer
57
views
Save button in Laravel Blade + JavaScript fetch not triggering (no console log, no network request)
I’m working on a Laravel Blade view (monitoring.blade.php) where I have an edit and save button for each row. The edit button works, but when I click the save button, nothing happens — no console logs,...
4
votes
1
answer
132
views
Why I cannot send body with a fetch request when mode is no-cors?
Trying to make a cross-origing fetch request with the no-cors mode I found out it is not possible in this case to send any data to the server as a body:
const url = 'http://cross-origin-example.com/...
433
votes
19
answers
439k
views
How do I POST a x-www-form-urlencoded request using Fetch?
I have some parameters that I want to POST form-encoded to my server:
{
'userName': '[email protected]',
'password': 'Password!',
'grant_type': 'password'
}
I'm sending my request (currently ...
571
votes
14
answers
881k
views
Setting query string using Fetch GET request
I'm trying to use the new Fetch API:
I am making a GET request like this:
var request = new Request({
url: 'http://myapi.com/orders',
method: 'GET'
});
fetch(request);
However, I'm unsure how ...
547
votes
13
answers
1.3m
views
Trying to use fetch and pass in mode: no-cors
I can hit this endpoint, http://catfacts-api.appspot.com/api/facts?number=99 via Postman and it returns JSON
Additionally I am using create-react-app and would like to avoid setting up any server ...
2
votes
1
answer
149
views
Why does setTimeout execute before fetch .then despite microtask priority? [duplicate]
I'm running the code below. The output I was expecting was:
Start -> End -> While expires -> joke -> setTimeout
However, the output I’m actually getting is:
Start -> End -> While ...
327
votes
18
answers
473k
views
Fetch API request timeout?
I have a fetch-api POST request:
fetch(url, {
method: 'POST',
body: formData,
credentials: 'include'
})
I want to know what is the default timeout for this? and how can we set it to a ...
241
votes
42
answers
499k
views
React Native fetch() Network Request Failed
When I create a brand new project using react-native init (RN version 0.29.1) and put a fetch in the render method to the public facebook demo movie API, it throws a Network Request Failed. There is a ...
450
votes
13
answers
545k
views
Retrieve data from a ReadableStream object?
How may I get information from a ReadableStream object?
I am using the Fetch API and I don't see this to be clear from the documentation.
The body is being returned as a ReadableStream and I would ...
1
vote
0
answers
121
views
Why does my API call in Next.js return undefined even though the Express backend works fine?
I’m building a small full-stack project using Next.js (frontend) and Express.js (backend) with a MySQL database.
The Express backend has this route:
// server.js
import express from "express&...
0
votes
1
answer
66
views
TMDb API Error: signal timed out when fetching popular movies
Problem:
I’m trying to fetch popular movies from the TMDb API in my Next.js project, but I keep getting a signal timed out error.
Here’s the error log:
TMDb API Error: signal timed out
at ...
370
votes
12
answers
570k
views
Fetch API with Cookie
I am trying out the new Fetch API but is having trouble with Cookies. Specifically, after a successful login, there is a Cookie header in future requests, but Fetch seems to ignore that headers, and ...
0
votes
1
answer
75
views
Why doesn't useState update correctly in my custom useFetch hook?
I'm trying to write a custom React hook that fetches data. It seems to work partially — but loading goes false before data is set, and error is never set even when a request fails.
import { useState, ...
0
votes
0
answers
90
views
How does a .NET Controller know to apply the CancellationToken = default [duplicate]
EDIT 2 (please reinstate this question)
As (see below) the CancellationToken is NOT sent from caller to callee of an API, how does .NET C# know to apply the default= option of a Controller methods' ...
419
votes
11
answers
690k
views
How do I post form data with fetch api?
My code:
fetch("api/xxx", {
body: new FormData(document.getElementById("form")),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
// "Content-Type": "multipart/...
349
votes
12
answers
216k
views
What is difference between Axios and Fetch? [closed]
I'm trying to call a web service for my application, and there are two options available: Fetch and Axios. I'm not sure which one to choose, so I'm looking for information to help me decide. Can you ...
269
votes
14
answers
561k
views
Fetch: reject promise and catch the error if status is not OK?
Here's what I have going:
import 'whatwg-fetch';
function fetchVehicle(id) {
return dispatch => {
return dispatch({
type: 'FETCH_VEHICLE',
payload: fetch(`http:...
353
votes
11
answers
500k
views
How do I upload a file with the JS fetch API?
I am still trying to wrap my head around it.
I can have the user select the file (or even multiple) with the file input:
<form>
<div>
<label>Select file to upload</label&...
209
votes
19
answers
1.0m
views
Getting "TypeError: Failed to fetch" when the request hasn't actually failed
I'm using fetch API within my React app. The application was deployed on a server and was working perfectly. I tested it multiple times. But, suddenly the application stopped working and I've no clue ...
-1
votes
1
answer
67
views
Updating the cart by fetch request
I have a code for updating the quantity in the cart by a fetch() request, and I modified it a little:
updateMainItem(line, quantity, name, variantId) {
const body = JSON.stringify({
line,
...
194
votes
19
answers
494k
views
React useEffect causing: Can't perform a React state update on an unmounted component
When fetching data I'm getting: Can't perform a React state update on an unmounted component. The app still works, but react is suggesting I might be causing a memory leak.
This is a no-op, but it ...
183
votes
12
answers
215k
views
JavaScript fetch - Failed to execute 'json' on 'Response': body stream is locked
When the request status is greater than 400(I have tried 400, 423, 429 states), fetch cannot read the returned json content. The following error is displayed in the browser console
Uncaught (in ...
0
votes
0
answers
29
views
Importing @babel/traverse breaks files
As the title says.
This code reproduces the issue.
My environment: Windows 11, ArchWSL, Volta, [email protected], [email protected]
import fs from "node:fs";
import { Buffer } from "node:buffer&...
332
votes
8
answers
232k
views
How do I cancel an HTTP fetch() request?
There is a new API for making requests from JavaScript: fetch(). Is there any built in mechanism for canceling these requests in-flight?
-4
votes
1
answer
124
views
Asynchronously and quickly make many API requests in JavaScript while handling or preventing 429 CORS error messages [closed]
How can I asynchronously create two hundred API requests in a quick manner to an API, that is https://api.dictionaryapi.dev, in JavaScript? I want to catch CORS errors with an error status of 429 ...
301
votes
9
answers
376k
views
Basic authentication with fetch?
I want to write a simple basic authentication with fetch, but I keep getting a 401 error. It would be awesome if someone tells me what's wrong with the code:
let base64 = require('base-64');
let url =...
35
votes
3
answers
46k
views
Angular detected that `HttpClient` is not configured to use `fetch` APIs. (Angular 17 - SSR)
I got this error after updating to angular 17:
NG02801: Angular detected that `HttpClient` is not configured to use `fetch` APIs. It's strongly recommended to enable `fetch` for applications that use ...
1
vote
1
answer
63
views
Why does my async function return a pending Promise instead of the expected value in JavaScript? [duplicate]
I’m trying to call an async function and get the result, but instead of the actual data, I get a pending Promise. Here’s a simplified version of my code:
async function getData() {
const response = ...
228
votes
15
answers
216k
views
Upload progress indicators for fetch?
I'm struggling to find documentation or examples of implementing an upload progress indicator using fetch.
This is the only reference I've found so far, which states:
Progress events are a high-level ...
3
votes
1
answer
306
views
How to pass a List of strings as FormData to FastAPI using JavaScript Fetch API?
This is the Next.js frontend:
// Create FormData to send files, URLs and username to the API
const formData = new FormData();
if (files && files.length > 0) {
files.forEach((file) =>...
-2
votes
1
answer
102
views
doPost(e): e.postData is Undefined for POST Request from Netlify with application/json [closed]
I'm building a website hosted on Netlify that submits a form to a Google Apps Script web app. The form data is sent as JSON with the Content-Type: application/json header using the fetch API.
The ...
0
votes
2
answers
314
views
How can I automatically refresh the token and retry the fetch request after receiving a 401 response?
const acceptRequest = async () => {
try {
const res = await fetch(`${process.env.NEXT_PUBLIC_SOCKET_SERVER_URL}/acceptRequest`, {
method: "POST",
body: JSON....
196
votes
12
answers
304k
views
How can I download a file using window.fetch?
If I want to download a file, what should I do in the then block below?
function downloadFile(token, fileId) {
let url = `https://www.googleapis.com/drive/v2/files/${fileId}?alt=media`;
return ...
20
votes
5
answers
21k
views
Increase timeout in nodejs built in fetch API
I am using the Fetch API introduced in NodeJS 18 to access an API. However, the request always times out after 10 seconds with the following error message.
TypeError: fetch failed
at Object.fetch (...
31
votes
10
answers
93k
views
next.js fetch request gives error TypeError: fetch failed [duplicate]
I'm setting up a next.js website with strapi but running into an issue with my fetch request. When I make the request in postman I can see the data is returned so the endpoint is correct.
The error I ...
230
votes
7
answers
193k
views
How to check if the response of a fetch is a json object in javascript
I'm using fetch polyfill to retrieve a JSON or text from a URL, I want to know how can I check if the response is a JSON object or is it only text
fetch(URL, options).then(response => {
// how ...
50
votes
4
answers
76k
views
Next.js: TypeError: Failed to parse URL from ... when targeting API route relatively
I have this code in my app/page (Server Component):
const getUsers = async () => {
const result = await fetch('/api/users', {method: 'GET'});
if (result.ok) {
return result.json();
}
...
253
votes
7
answers
206k
views
Why does .json() return a promise, but not when it passes through .then()?
I've been messing around with the fetch() api recently, and noticed something which was a bit quirky.
let url = "http://jsonplaceholder.typicode.com/posts/6";
let iterator = fetch(url);
iterator
...
19
votes
6
answers
26k
views
Next.js does not send cookies with fetch request even though credentials are included
I'm working on a Next.js application which was originally a normal react app (created with create-react-app) and I am trying to send cookies with a fetch request to my server. However, the cookies ...