fetch

How to wait a Promise inside a forEach loop

Deadly 提交于 2021-01-29 00:56:23
问题 I'm using some Promise() functions to fetch some data and I got stuck with this problem on a project. example1 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo1'); }, 3000); }); example2 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo2'); }, 3000); }); doStuff = () => { const listExample = ['a','b','c']; let s = ""; listExample.forEach((item,index) => { console.log(item); example1().then(() => { console.log("Fisrt"); s =

html form does not get sent after onSubmit function

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 20:01:10
问题 The geocodeAddress() function uses fetch to send a http request. Before I added "event.preventDefault()" as a parameter to the function, it would not run properly (TypeError: Network Error) as the request was being interrupted by the page reloading caused by the form being sent. However, once I added it, the form no longer gets sent. I don't think the problem lies with the php code as I have not altered it at all. What could be causing this? I had the same error in this post before 'TypeError

React Native render FlatList conditional

两盒软妹~` 提交于 2021-01-28 08:10:31
问题 I have a question regarding React Native FlatList. I have a FlatList that gets my dataZ state as the data prop - dataZ is an Array that gets filled in by my fetchcall. The response of my fetch call looks like this: [ { "activitydate": "2019-08-01T22:00:00.000Z", "phaseid": 7667, "time": 360, "userid": 138, "zkub": " " }, { "activitydate": "2019-08-04T22:00:00.000Z", "phaseid": null, "time": 456, "userid": 138, "zkub": "K" }, { "activitydate": "2019-08-05T22:00:00.000Z", "phaseid": null, "time

fetch API always returns {“_U”: 0, “_V”: 0, “_W”: null, “_X”: null}

此生再无相见时 提交于 2021-01-28 07:15:26
问题 The below code always return the below wired object {"_U": 0, "_V": 0, "_W": null, "_X": null} as response. Here is my code getData = () => { fetch('http://192.168.64.1:3000/getAll',{ method: 'GET', headers: { Accept: 'application/json', 'Content-Type': 'application/json' } }) .then((response) => { console.log('Response:') console.log(response.json()) console.info('=================================') }) .catch(err => console.error(err)); } componentDidMount(){ this.getData(); } I am using

React update state variable with JSON data

╄→尐↘猪︶ㄣ 提交于 2021-01-28 06:29:15
问题 App.js: function App() { const [items, setItems] = useState([]); useEffect(() => { const searchDB = () => { fetch("http://127.0.0.1:8443/subColumns/5/?key=fc257229-8f91-4920-b71f-885403114b35", { mode: 'cors', credentials: 'include' }) .then(res => res.json()) .then((json) => { setItems(json); }) console.log({items}); } searchDB(); }, []) I need to keep the json response in a state varibale because in the future, the API request will nt be hard coded and I expect the user will make multiple

React App: How to display data from api using fetch

北城以北 提交于 2021-01-28 06:18:02
问题 I am trying to display school data from an external api using React. I'm just trying to display a school name to start. The school name appears in the console, but it doesn't show up in the browser.The api call is correct, as it works in Postman. Here is my code: import React, { Component } from 'react'; import './App.css'; class App extends Component { constructor(props) { super(props); this.state = { schoolName: '', // schoolData: {} } } fetchSchool(event) { event.preventDefault(); const

await is only valid in async function error for a async function [duplicate]

喜夏-厌秋 提交于 2021-01-28 05:03:29
问题 This question already has answers here : await is only valid in async function (9 answers) Closed 8 months ago . I am fetching 2 URLs at the same time using Promise all but when I am calling this function using await (as getAllURLs is async function) it gives me an error, How can I solve this problem? const fetch = require("node-fetch"); let urls = ["https://jsonplaceholder.typicode.com/users","https://jsonplaceholder.typicode.com/users"] async function getAllUrls(urls) { try { var data =

Fetch Data from json file in React.js

陌路散爱 提交于 2021-01-28 02:02:18
问题 I have a json file call data.json such as ( I use React.js): [{"id": 1,"title": "Child Bride"}, {"id": 2, "title": "Last Time I Committed Suicide, The"}, {"id": 3, "title": "Jerry Seinfeld: 'I'm Telling You for the Last Time'"}, {"id": 4, "title": "Youth Without Youth"}, {"id": 5, "title": "Happy Here and Now"}, {"id": 6, "title": "Wedding in Blood (Noces rouges, Les)"}, {"id": 7, "title": "Vampire in Venice (Nosferatu a Venezia) (Nosferatu in Venice)"}, {"id": 8, "title": "Monty Python's The

Fetch external audio file into web audio API buffer - cors error?

假装没事ソ 提交于 2021-01-28 01:34:07
问题 I'm working on a project which I hoped would take random selections from the xeno-canto archive to create a 'virtual dawn chorus' I'm doing this in javascript with the webAudio API. I have a list of samples and their urls such as xeno-canto.org/sounds/uploaded/YQNGFTBRRT/XC144576-ABTO_BWRNWR_15Apr2013_Harter.mp3' Which I'm tyring to load into an audio buffer. This is my 'loadAudio' function in javascript. I've successfully used this in other projects to get my audio - although that was from

multer, react native image picker image upload not working on iOS

北城以北 提交于 2021-01-28 00:46:16
问题 I am having great trouble in uploading an image via fetch and react-native-image-picker to multer and express js backend. Below is my react native code. try { const data = new FormData(); data.append('image', { name: photo.fileName, type: photo.type, uri: Platform.OS === 'android' ? photo.uri : photo.uri.replace('file://', ''), }); data.append('id', id) fetch(`${API}save-image`, { method: 'POST', body: data, }) .then(response => response.json()) .then(response => { console.log('upload succes'