Most voted "fetch" questions
The Fetch API provides an interface to search for resources (for example, across the network) asynchronously in Javascript. It will look familiar to anyone who has used Xmlhttprequest, but the new API offers a more powerful, flexible and responsive feature set to new versions of the Ecmascript standard.
Learn more…49 questions
Sort by count of
-
11
votes2
answers388
viewsAsynchronous return of some Apis
Why the return of some Apis are exactly the result we want (for example, a JSON) and some others return an object full of functions and objects? Example API that directly returns the result I want:…
-
10
votes3
answers195
viewsWhy do I need to spend two then on AJAX requests made with the fetch API?
In the example of the following request: fetch("https://viacep.com.br/ws/01001000/json/") .then(resposta => resposta.json()) .then(json => console.log(json)); In the first then should not…
-
6
votes1
answer93
viewsWhat are the main types accepted by the Fetch API for the HTTP request body?
I know I can use the API fetch to perform HTTP requests by browser. And I know I can use the property body to configure the body of the request. But I would like to better understand which types I…
-
2
votes1
answer357
viewsHow to execute a synchronous request in a looping
In the example below let arr = [ { 3 : 'teste' }, { 5 : 'teste' }, { 1 : 'teste' }, { 2 : 'teste' }, { 0 : 'teste' }, { 4 : 'teste' } ]; arr = arr.sort( ( a , b ) => { return Object.keys(b)[0] -…
-
2
votes0
answers127
viewsFetch request with ASP . Net Core 3.0
I am trying to replace the Ajax methods by Fetch in the application, but I cannot receive an object with Fetch, I made a small test object to try to receive, in Ajax, with you passing parameter…
-
2
votes0
answers45
viewsHow to pick up values from an object passed by fetch by PHP
var dados = { id: 1234, nome: "Teste", tipo: "pagamento" }; fetch('dados.php', { method: 'POST', body: JSON.stringify(dados), headers: { 'Content-Type': 'application/json' } }) I received this help…
-
2
votes2
answers164
viewsuse fetch api to present user cards, innerHTML overwrite cards
In this code I access a fake Rest api, I take the data, step for json, but when it comes to presenting the cards of the users I cannot find a good way to do this, innerHTML erases all the cards and…
-
2
votes1
answer1589
viewsReact fetch() POST
I have a API (POST) in which I pass some parameter and it returns me results and the question is the following: I got a guy Dashboard where I have to take DIA data and MES data (using the same API,…
-
1
votes1
answer579
viewsWhy use Redux to request the API in React?
I started to see React well before learning how to use Redux and always requested in the API using a Fetch or Axios in the component itself. Today I already venture into the world of Redux and come…
-
1
votes0
answers318
viewsHow to hide error message coming from an API using Ajax, Fetch or Axios
Good evening guys, I’m beginner with Javascript, and I’m developing the functionality of a CRUD, I want to use the correct HTTP verbs for each function (Obs: I know that using the HTTP verbs is only…
-
1
votes1
answer1340
viewsSending body parameter via fetch API
I am trying to send a request asynchronously via javascript to the backend in Node, follow the front code: if ( window.location.pathname.indexOf('/') != - 1 ||…
-
1
votes2
answers42
viewsinsert value into a Json data request
I need to write a function that accesses a specific field within a Json file. Json fields are listed as id1, id2, id3... and the value to be accessed will be passed by the function itself. My…
-
1
votes1
answer160
viewsHow to get the content of an image correctly using fetch?
Using the function fetch I need to get the contents of an image obtained from the server response. The problem is that this image is coming with different content than it should. Using "requests" in…
-
1
votes0
answers54
viewsDoubt Fetch + React Native
beauty? I am developing an App with Expo for a client, but when I consult (via barcode) its API, always the first time returns an empty Array, if I do the query then the data is returned. Can you…
-
1
votes1
answer360
viewsSend Formdata with Fetch API
I’m trying to send a Formdata() to the backend via Fetch API, but I can’t read the form inputs in NODEJS. By the way, req.body is empty. I’m wearing the body-parser and express. Backend: const…
-
1
votes1
answer111
viewsHow to return the value of a function that uses Javascript promises?
I have a function that should check if a user is enrolled in Stripe. For this is made a request to a third server that returns an array of users. When I make the request, a promise is returned:…
-
1
votes1
answer162
viewsJavascript pass more than one parameter through the fetch
In the link below, I managed to send a parameter via fetch by body, but I need to send more than one, for example, values of a form. I need an example, using POST to send through the body, for…
-
0
votes0
answers44
viewsRequest with FETCH API keeps repeating
When I send the form to the server, the data is usually recorded in the database. However, when looking at the network of my browser, there are always two requests sent, as below: 1 - sendAjax @…
-
0
votes1
answer395
viewsI cannot access the data using the fetch API
I have a URL that returns data in JSON: [ { "id": 21, "solicitante": "Joao", "chamado": "coisa aqui no lab" }, { "id": 22, "solicitante": "Maria", "chamado": "projetor deu pau" } ] On another page,…
-
0
votes1
answer297
viewsReturn value from inside fetch
I’m trying to read a local Javascript file and put your data into a variable and so far I’ve written the following code: function fetchDictionary() { const URL_TO_FETCH = './lang-portuguese.txt';…
-
0
votes0
answers67
viewsTwo questions regarding the use of the Corsregistry.allowOrigins() method
I’m trying to do a post type resquest with credentials (token) for my spring boot built api. But I’m having trouble specifying the source I pass as a parameter to the method…
-
0
votes1
answer52
viewsObject key is not recognized after using fetch
The console indicates a wrong saying Uncaught Typeerror: Cannot read Property 'name' of Undefined. within the scope of the function in which API access can access name and other keys. the code:…
-
0
votes1
answer75
viewsCancel Fetch Using Componentwillunmount in React JS
Good evening. I’m having doubts about such a life cycle method of React and I’m doing tests. One of them is to cancel a request fetch, however, I’m not getting it. The console log. appears, but the…
-
0
votes1
answer782
viewsFetch function in Javascript returns Undefined
Hello, I did a little function called makeRequest, which, by receiving a URL as a parameter, makes a simple GET request to the URL using the FETCH method. I’m using a simple github endpoint, where…
-
0
votes1
answer138
viewsHow to open an HTML document from fetch in the same tab?
I’m creating a riddle site in which each riddle, the user must insert an answer on prompt and this reply will be sent to the server by POST request with the function fetch. On the server side, the…
-
0
votes1
answer272
viewsReturn fetch js result on a global variable
Hi, sorry about the layman’s question. Basically I want to use the fetch return and put in a variable, I can use it in other functions to make 1 request only, today I’m using const xhr =…
-
0
votes1
answer530
viewsRequest fetch for Php api shows all the elements of the request instead of the return json
Hello I have an API that receives parameters and returns a correctly answer in tools like Internet but in my front end I receive all the request and not the response message in the body of the…
-
0
votes1
answer125
viewsMultiple image upload with Fetch API
I have the following code: HTML: <input type="file" name="image[]" class="selecao_arquivo" id="selecao_arquivo" multiple> Javascript: sendInsucesso.addEventListener('click', e => {…
-
0
votes2
answers56
viewsIs it appropriate to use If-Else in a function along with Fetch?
I’m creating a function with a . fetch to get data from openweathermap.org, which by definition returns in Fahrenheit. Is it acceptable from the point of view of Clean Code, which says that the…
-
0
votes1
answer419
viewsBad Request 400 - Using Fetch API
I’m having trouble accessing my api using POST method. This is my requisition: function createTool(token, obj) { return fetch(`${url}/tools`, { method: 'POST', headers: { Authorization: token, },…
-
0
votes1
answer253
viewsPagseguro API 401 error - Unauthorized; Error logging in paid
[RESOLVED] I made a simple Node server to test the Pagseguro API and am having problems with error 401. In a video I saw that to make requests for the Pagseguro API it is necessary to have an SSL…
-
0
votes0
answers47
viewsI’m unable to use fetch API
I’m unable to use fetch API I don’t know what’s wrong with my code. fetch('http://localhost:5000') .then(res => res.json) .then(data => console.log(data)) In the http://localhost:5000 has that…
-
0
votes1
answer51
viewsfetch receiving http status 0
I created a small project on webstorm with an html that fetch from my localhost:3340 fetch('http://httpbin.org/get') .then( function(response){ console.log("response ok"); return response.json(); }…
-
0
votes0
answers37
viewsBackend not receiving body of the request via AXIOS or Fetch
I’m trying to make a POST request via fetch and via Xios, but something is happening that the request arrives without the body. I used Postman to see if it could be some problem in the backend,…
-
0
votes0
answers26
viewsHow to get something in the api header?
Guys as they are? I have a little problem to get the header of a request via fetch or Next... using insomnia the header appears However when I make a request via Xios or fetch it does not return…
-
0
votes0
answers13
viewsHow to assign the return of a Fetch function to Javascript variables
Maybe the solution to my problem is extremely trivial, because I do not understand much of Javascript, however I did not find the solution. I have developed an API and intend to consume it so that…
-
-1
votes1
answer490
viewsGet fetch return with await/async
recebe(); async function recebe(){ const {url} = await pegaValores(); console.log(url); } async function pegaValores(){ return fetch('http://www.mocky.io/v2/5dba68fb3000007400028eb5')…
-
-1
votes1
answer85
viewsconsole.log returning "Undefined" no then (fetch)
I am beginner, apparently the "code" is inside an id, n know how to capture... const url = 'https://economia.awesomeapi.com.br/json/USD-BRL/' fetch(url) .then(resposta => resposta.json())…
-
-1
votes1
answer16
viewsFetch.Azy keeps loading the attribute what can it be?
Even if I use Azy my list is loaded, someone knows what’s going on? public class Departamento { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotEmpty(message="O campo…
-
-1
votes1
answer7
viewsShow text on page from Django database
Hello, I’m trying to display a text from the mysql database, using Django, I’ve searched for several tutorials but nothing works, if anyone can help thank you already. This is part of my file:…
-
-1
votes0
answers12
viewspage keeps giving Reload every time and Fetch function is executed
const form = document.getElementById('form') form.addEventListener('submit', function (e) { e.preventDefault(); const firsName = document.getElementById('firstname') const lastName =…
-
-2
votes1
answer224
viewsFetch always returns "Typeerror: Body has already been Consumed." How to fix?
I’m using the function fetch down below: var url = "https://jsonplaceholder.typicode.com/users/2"; fetch(url).then(function(response) { if (!response.ok) { alert("Response not ok" +…
-
-2
votes1
answer286
viewsI’m not able to send a POST to PHP by Javascript fetch
I’m trying to send a POST to PHP using fetch, the code is like this: <button onclick="fnConsultarDadosPost()">Consultar com POST</button> <button…
-
-2
votes2
answers142
viewsHow to sort an object with Javascript?
I’m creating a function that takes elements from a . json file and creates options for a select in HTML dynamically. This file is ordered, but when it is presented in HTML it is disordered. Example…
-
-2
votes1
answer125
viewsHow to send id as parameter to url
I am training to build a blog, I can already recover the posts via API and display the results on the screen, but I need now when you click on the item (post), its id is sent to the url, forming…
-
-2
votes2
answers219
viewsQuestions when returning data from an API to html?
The problem is that by clicking the convert button it consumes the API E shows the correct quote in the debug and console. But in time to pass the value moedaBVal = cotaçao * moedaAVal he passes as…
-
-3
votes1
answer25
viewsthis.state.value returning Undefined when it is changed
I am developing a system and a part of it will be register and edit the schedules, I am able to return the data of times on the screen, but when I try to edit and click on the button to give an…
-
-3
votes1
answer82
viewsReturn Undefined in html for JSON object request
I’m trying to return JSON objects from an api, only when the elements are rendered in HTML, the value passes to Undefined. I believe it is something with the request in appenChild, since it returns…
-
-4
votes2
answers696
viewsHow to upload the contents of a variable to the backend using javascript fetch?
I can’t replace ajax with fetch I’m taking all libraries out of my code, and I’m trying to make the most of the resources pure javascript offers, like fetch. However, I am not able to make a request…
php javascript ajax fetch internal-server-errorasked 4 years, 9 months ago Matheus Ricardo Brunelli 1