Questions tagged [fetch-api]
The Fetch API is an improved replacement for XHR, for making asynchronous HTTP requests while better managing redirects and interaction with CORS and Service Workers.
3,527
questions
0
votes
0
answers
8
views
How to fetch Wikipedia site?Access to fetch at * from origin * has been blocked by CORS policy [duplicate]
I am tring to display website from wikipedia on my site but i have problem with cors.
Please can somone help me? I tried so many things but nothing work for me.
error:
Access to fetch at 'https://en....
0
votes
0
answers
14
views
send image ad a field of json with fetch - javascript
i have a payload for fetch body that is like below
{
"name": "test",
"description": "test",
"images": {}
}
the problem is the images field is ...
0
votes
0
answers
7
views
Why does Prettier remove quotes from "Authorization" header in fetch request? [duplicate]
Is it acceptable to send a fetch request with the Auth header not formatted as a string?
fetch('...', {
method: POST,
headers: {
Authorization: 'Bearer...',
'Content-type': 'application/...
-1
votes
0
answers
10
views
Confusion about chaining promises in JavaScript
Please correct my sentences if I am wrong :
The then method is available on all promises.
This method ALWAYS returns a Promise object,
It does NOT matter if we return a value from its callback ...
0
votes
0
answers
17
views
Do not work request fetch inside observer
I have an observer that does a check for the existence of an element in the DOM. And also, inside observer I have a fetch request which doesn't work.
Please help with the code, or explain why it doesn'...
0
votes
0
answers
29
views
POST Request adding table row to SQL DB without data
I'm sending a rq to my psql that is working because it is updating my db with an extra row on every click (in the right table too). The problem is, it isn't adding in data to that table. I'm trying to ...
0
votes
0
answers
11
views
Curl Request with fetch (image upload)
I'm trying to upload an image to an API.
In the doc they give me the CURL command:
curl -i --upload-file ~/Desktop/Myimage.jpg -H 'Authorization: Bearer Redacted' "https://api.xxx.com/mediaUpload/...
0
votes
1
answer
29
views
How do I upload images with fetch api using form-data
I am creating a registration form where a user can choose to upload their profile picture or have a default picture set up.
I am using a flask app I created myself as the backend and vue frontend. I ...
0
votes
0
answers
20
views
User Agent missing error in ReactJS fetch api
I am using News API in ReactJS for fetching news using fetch API.
CODE FRAGMENT
const url = `https://newsapi.org/v2/top-headlines?country=in&category=${this.props.category}&pageSize=${this....
-1
votes
0
answers
5
views
Not able to access jenkins using fetch API, getting "CORS Blocked Error"
I am getting the following error,
Access to fetch at 'http://ec2-44-199-*-.com**te-1.amazonaws.com:8080/job/Job1/api/json?build=pretty' from origin 'http://localhost:3000' has been blocked by CORS ...
-1
votes
0
answers
9
views
Can't loop over Array created from Fetch() [duplicate]
I use Fetch() to retrieve data from an api end point. The data is fetched with no errors.
The data is a record from a database. I want to use this data to dynamically build a HTML table. However, when ...
0
votes
1
answer
41
views
Waiting until eventListener is called to return a promise
I'm trying to return the result of a fetch call but I want to wait until my eventListener detects a change within a dynamically rendered selector list.
You'll see the fetch call written below grabbing ...
2
votes
0
answers
33
views
React Query invalidateQueries updating data after post
I'm working on a simple React CRUD with React Query, and I've being stuck for a while trying to update my fetched data after I post a new item with invalidateQueries but it doesn't work, being trying ...
-1
votes
2
answers
74
views
Async await with Fetch
my fetch works perfectly with .then, but i want to step it up a notch by using async and await. It should wait for all 5 API calls, and then place the answer, instead, it shows answer on every API ...
0
votes
1
answer
19
views
Node/Express logging the correct response, but React frontend logging something completely different
I'm working on a form for a ecommerce site that allows the admin/owner to upload Images to Cloudinary.
The image is uploading to Cloudinary successfully, and when I log the response (console.log(...
-2
votes
0
answers
24
views
Using Javascript to tell Express server to serve a new webpage to multiple clients
In my web-based game, one player performs an action that forces all players to then be taken to a new page. I'm simply trying to send this request from the client Javascript to the Express server, ...
0
votes
0
answers
36
views
Update Component after post new item to the Database sveltekit
I want to update the todo after adding a new todo which gets stored into the backend and updates the previously displayed component with the new one which has a new todo.
Here is my TodoStore.js file ...
0
votes
1
answer
27
views
How to to put fetched data into the state?
I am trying to put fetched data into the state but it's not working, please let me know what I am doing wrong here, and also I want specific data to be inside the state like in this example I want ...
0
votes
1
answer
28
views
Fail to send JSON HTTP POST, but succeed to send text HTTP POST. why?
I want to send a JSON http POST from an HTML page. The Fetch API is used here.
It can be successfully posted if the content-type is "application/x-www-form-urlencoded" or "text/plain&...
0
votes
1
answer
17
views
Weird Google Places Find Place API parsing fields parameter error with certain fields (not deprecated)
I try to run the google places "findplace" from text API. When I run it for the basic parameters, it works. However, when I add on the international phone number and website parameters it no ...
1
vote
1
answer
22
views
Redirect for HTTP POST does not work in SvelteKit
In SvelteKit I want to handle a post request and redirect to a route on success. This should be possible by sending a status code of 303 and the location header - as in the SvelteKit docs. ...
0
votes
2
answers
39
views
Get json data from from django-rest-api with react frontend into a variable
I am new to react and javascript. I am trying to get some data INTO A VARIABLE in react from django-rest API.
I am using this variable in another function using react-beautiful-dnd.
I have the API set ...
0
votes
0
answers
23
views
Fetch TypeError: Network request failed React Native
I try do the next fetch with react-native android 12 API 28
(import FormData from 'form-data';)
let formData = new FormData();
const file = new File(["foo"], "foo.txt",
...
0
votes
0
answers
32
views
How can I optimize javascript code against fetch api?
I want to use fetch api on my wordpress site. I watched many tutorials like Promise, Callbacks Async / Await. Fetch api related examples are usually on json post requests. How can I develop this code ...
0
votes
1
answer
22
views
Why I cant call useRouter hook inside getServerSideProps in next.js [duplicate]
I want to fetch data according to id. I have the id in my URL. So I need to get that id from the URL using useRouter. But when I call useRouter inside getServerSideProps for fetching data on the ...
-2
votes
0
answers
28
views
Porque error do fetch não está caindo no catch? [closed]
Estou com problema em uma função async/await, todo o código está funcionando conforme o esperado, o usuário digita o username de uma conta no github e a function getGithubProfile solicita da Api do ...
-2
votes
0
answers
10
views
JSON error when try to fetch data from PHP [duplicate]
I'm trying to get data from a PHP page in JSON format. But I get this error:
VM918:1 Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
My PHP codes:
$post = json_decode(...
1
vote
1
answer
49
views
Updating password using 'PUT' method
can someone help me to understand how to use the query function created to update a password in my database?
here is the query function in question
async function updatePassword(req, res) {
return db....
-1
votes
0
answers
16
views
React fetch data then render
Hey there I'm having trouble understanding data fetching in React as I'm very new to the development in React. If this question is a duplicate kindly redirect me. Thank you.
The problem is this. I'm ...
0
votes
1
answer
27
views
Use declarativeNetRequest to set the "Referer" header when using fetch() in a chrome extension (V3)
Im working on a chrome extension using manifest V3. A core functionality of the extension is to enable users to send data from a website to the REST API of my django application, where the user is ...
0
votes
1
answer
37
views
Infinite scroll in Next.js doubles the last element on first fetch
I have a project that is based on Next.js fetching from Strapi Rest API. I'm fetching and rendering cards based on the content on the fetch. Since I don't want to load everything at once I implemented ...
0
votes
0
answers
33
views
Hello i need to get the fastest response, all successful (which means ignore the rejected) and three first responded
I've already tried to get the fastest response but in chrome toolbar network i see all the responses but not the fastest. Also as i mentioned above I want to get all the successful responses and ...
0
votes
1
answer
32
views
Sending form data from react client side to node.js server side
I have a login form at the client side (react) that I try to submit and pass the credentials to the login function at the server side (node.js)
when I use postman to send raw json object with the user ...
-2
votes
1
answer
45
views
Create a file object of zip file based on a blob for formdata in a fetch
I would like to upload a zip file as part of formdata in a Javascript fetch.
I can easily send in a zip file which I have read in via a file input control (see first segment of code). But when try to ...
-1
votes
0
answers
16
views
jQuery .load method failing. Doesn't use specified file path
I have an index.html with my navigation bar in it, I was originally able to pull this into other pages after about 4 hours of trial and error (my script was in the wrong place). Now that I'm trying to ...
0
votes
3
answers
49
views
React native: async, await, fetch
In my app, I'd like to perform an HTTP request, wait for the request to be completed, and show the result
function HomeScreen({ navigation, route }) {
....
console.log("Try to decode");
...
3
votes
2
answers
72
views
How to update the state after a data update through an API request in React?
I have a small problem. I have this fetch data in one component which is working perfectly:
const [item, setItem] = useState([]);
const [loading, setLoading] = useState(false);
useEffect(() => ...
0
votes
1
answer
31
views
Store fetch data in a variable and use entire json as a prop in a react component
i have the next code, the app should get a json from an api and then pass the entire json as a prop so it can be treated in each component file and return the element to the screen.
The thing is i ...
3
votes
1
answer
130
views
Failing fetch-api request (GET AND POST). I am so lost
I've written code for money for 20+ years, I have no excuse for this question though.
And oh boy have I googled it. I know that there are many semi-identical questions here, and I think I have read ...
0
votes
0
answers
11
views
How to read a PromiseResult and store it in a global variable [duplicate]
I am trying to read out some json from an api and store that json in a global variable for easy use later on. the problem is that after I return my async function I get a succesful promise with my ...
-1
votes
0
answers
26
views
Cross-Origin problems when trying to send a POST request
I'm working on the frontend of a website with vanilla JS and I'm trying to use the Hapio API which basically allows you to book appointments. In order to create a new service (It's a barbershop ...
-1
votes
1
answer
37
views
Fetch multiple posts from JSON Placeholder with one API call
So, my question is, can you fetch multiple posts from JSON Placeholder API, but call fetch once, and fetch 12 posts for example. This is what I did so far, but when I go into network in inspect ...
-1
votes
1
answer
41
views
Why is `.then()` processed when fetch fails?
Consider the following code where I tried to shield fetch against any unsuccessful connections (I call them non "200-ish" in the comments) and provide a function that will make use of its ...
0
votes
1
answer
63
views
fetch() fails in Chrome extension under Windows but not MacOS
Introduction (added in edit):I am working on a Chrome extension that I want to be able to communicate with a server using fetch(). When I included such a feature in the new version of the extension, I ...
1
vote
2
answers
53
views
I can't take the information of my result of fetch. Promise
When I try to take the result of my API I can't.
my code:
export async function validLoginFetch(email,password){
const data = JSON.stringify({ email, password });
let headers = {
'...
0
votes
1
answer
36
views
Fetch Elastic API with query Javascript
i have elastic API and i try to fetch it with javascript and query on the fetch, but i don't know where to place the query, i only know how to fetch it just with authorization, can we fetch the ...
0
votes
2
answers
41
views
How to nest JSON inside "data:"{} object for POST fetch request?
Long time listener, first time caller.
I've created a form and sending a fetch request to my database (Xano).
My JSON object looks like the below snippet.
{
"job_type": "full-time&...
0
votes
2
answers
60
views
How can I call an API 2 million times quickly and write the returned value into my dataframe?
I have a problem. I have a dataframe that contains two addresses fromLat, fromLong to toLat, toLong. From these two addresses I want to calculate the distance by car and the duration. For this I use ...
0
votes
2
answers
45
views
how can i add function to sum of value in react js?
here i m trying to add function in which monthly, basic and hra value already substracted by some formula
but in netSalary i want to sum of all value when i fill all input
const onChange = (e) =&...
0
votes
0
answers
17
views
JavaScript post request returning as cancelled [duplicate]
window.post = function(url, data) {
return fetch(url, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});
}
post(url, {"rblxtoken": ...