axios

Send response from server side axios request to React/Redux app

拈花ヽ惹草 提交于 2020-01-02 12:58:20
问题 I'm a little new to creating a backend in Node/Express, but I am trying use axios to make HTTP requests. I've set up express routes that will make the necessary request and I know from using Postman that GET request I'm testing does return a response. Where I'm stuck is how to return that data and send it to my React/Redux app to use. -Server Side- //Express Route app.get('/api/recipes', recipeController.getRecipes) //Controller Function that makes axios request const axios = require('axios')

redirect after axios response with vue

混江龙づ霸主 提交于 2020-01-02 10:18:21
问题 Ok, so i have the following method. Basically I am calling an API backend, posting username and password, and if those pass, in the response, the server sends me a 200 status. What I want to do, is in the response, after I get the status, run an if/else, so if the status is 200, redirect, else display an error message. every time i try to use 'this.$router.push('/any route here')', I get an error: 'homepage.vue?3ec6:72 Uncaught (in promise) TypeError: Cannot read property '$router' of

Vue JS returns [__ob__: Observer] data instead of my array of objects

a 夏天 提交于 2020-01-01 22:47:28
问题 I've created a page where I want to get all my data from the database with an API call, but I'm kinda new to VueJS and Javascript aswell and I don't know where I'm getting it wrong. I did test it with Postman and I get the correct JSON back. This is what I get: [__ob__: Observer] length: 0 __ob__: Observer {value: Array(0), dep: Dep, vmCount: 0} __proto__: Array This is what I want: (140) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},

Getting 403 (Forbidden) when uploading to S3 with a signed URL

♀尐吖头ヾ 提交于 2020-01-01 08:17:50
问题 I'm trying to generate a pre-signed URL then upload a file to S3 through a browser. My server-side code looks like this, and it generates the URL: let s3 = new aws.S3({ // for dev purposes accessKeyId: 'MY-ACCESS-KEY-ID', secretAccessKey: 'MY-SECRET-ACCESS-KEY' }); let params = { Bucket: 'reqlist-user-storage', Key: req.body.fileName, Expires: 60, ContentType: req.body.fileType, ACL: 'public-read' }; s3.getSignedUrl('putObject', params, (err, url) => { if (err) return console.log(err); res

axios post request with json data

我与影子孤独终老i 提交于 2020-01-01 04:25:07
问题 I am using Axios JS library for sending post json request. but I am not receiving anything at the server. Here is my code const dt = JSON.stringify({"data":{"value":"gdfg1df2g2121dgfdg"}}); const request = axios.post(url, {dt}); I need to send post raw body in json format . 回答1: By default axios uses Json for posting data so you don't need to stringify your data. The problem could be that you're doing that. Could you try doing the post without it and check if it works? Also you don't need the

Multiple fields with same key in query params (axios request)?

南楼画角 提交于 2020-01-01 01:13:08
问题 So the backend (not under my control) requires a query string like this: http://example.com/?foo=5&foo=2&foo=11 But axios uses JS object to send the request params: axios.get('http://example.com/', { foo: 5 }); And obviously such object can't have multiple fields with the same key. How can I send a request with multiple fields with same key? 回答1: From the axios documentation on the request config // `params` are the URL parameters to be sent with the request // Must be a plain object or a

Axios ajax, show loading when making ajax request

て烟熏妆下的殇ゞ 提交于 2019-12-31 10:48:33
问题 I'm currently building a vue app and Im using axios. I have a loading icon which i show before making each call and hide after. Im just wondering if there is a way to do this globally so I dont have to write the show/hide loading icon on every call? This is the code I have right now: context.dispatch('loading', true, {root: true}); axios.post(url,data).then((response) => { // some code context.dispatch('loading', false, {root: true}); }).catch(function (error) { // some code context.dispatch(

Get API data with POST method in react-native with axios

假装没事ソ 提交于 2019-12-30 09:05:49
问题 I need to get data in react-native app with axios. I can get data with simple GET method as below: class AlbumList extends Component { state = { albums: [] }; componentWillMount() { //axios.get('https://rallycoding.herokuapp.com/api/music_albums') .then(response => console.log(response)); axios.get('http://rallycoding.herokuapp.com/api/music_albums') .then(response => this.setState({ albums: response.data })); } renderAlbums() { return this.state.albums.map(album => <AlbumDetail key={album

reactJS how to stop it listening to ajax request

六月ゝ 毕业季﹏ 提交于 2019-12-30 07:42:49
问题 I have ajax call in componentdidmount. And and then setState inside the ajax promise. The code is like this componentDidMount(){ axios.post('mydomian.com/item/',this.state) .then(function (response) { const res = response.data if (res.status === 'OK') { this.setState({items :res.list}) }else{ console.log('can not load data', response) } }.bind(this)) } componentWillUnmount(){ how to stop everything about axios? } This causes error 'can not setstate on an unmounted component', when I navigate

reactJS how to stop it listening to ajax request

佐手、 提交于 2019-12-30 07:41:26
问题 I have ajax call in componentdidmount. And and then setState inside the ajax promise. The code is like this componentDidMount(){ axios.post('mydomian.com/item/',this.state) .then(function (response) { const res = response.data if (res.status === 'OK') { this.setState({items :res.list}) }else{ console.log('can not load data', response) } }.bind(this)) } componentWillUnmount(){ how to stop everything about axios? } This causes error 'can not setstate on an unmounted component', when I navigate