axios

How to pass form values as FormData in reactjs on submit function

依然范特西╮ 提交于 2020-01-21 07:27:58
问题 I have a dynamic form generated using json data and I need to pass the form input values on submit. I'm planning to send the values as formdata. I have created submit function but i dont know how to append the values in formdata and need to pass through post method using Axios. Im new to react can anyone tell me how to do this. Below is my code. var DATA = { "indexList": [{ "Label": "Name", "Type": "text", "Regex": "", "Default_Val": "", "Values": { "Key": "", "Value": "" }, "Validtion Msg":

React: Axios Network Error

六月ゝ 毕业季﹏ 提交于 2020-01-21 04:05:30
问题 This is my first time using axios and I have encountered an error. axios.get( `http://someurl.com/page1?param1=1&param2=${param2_id}` ) .then(function(response) { alert(); }) .catch(function(error) { console.log(error); }); With the right url and parameters, when I check network requests I indeed get the right answer from my server, but when I open console I see that it didn't call the callback, but instead it caught an error. Error: Network Error Stack trace: createError@http://localhost

accessing response header via Axios

眉间皱痕 提交于 2020-01-17 08:22:28
问题 I'm using Axios to make a secure POST call to an API. This returns an URL within the response headers under 'Location'. I can see the URL being populated within Chrome's dev tools: but the response inside JS from Axios (below) doesn't contain this information: Any advice greatly received! 回答1: Possibly it occurs because you are doing a cors request that doesn't expose location header by default. You need to add this Cors Configuration to your server side app. Access-Control-Expose-Headers:

reactjs: after action redux not re-render

巧了我就是萌 提交于 2020-01-17 06:33:14
问题 I have a question, regarding updating a status in redux, I have this code that lists me a few elements and works well, now when I delete one of those elements also works, but the list is not updated after the delete click, I have to reload the page, to see the changes, some guide // Component listcomponent.js export default class listcomponent extends Component { constructor(props) { super(props); } render() { return( <div> {this.renderGroup()} </div> ) } renderGroup(){ return this.props

Axios get request gets all the data, unless I set state in the .then method in which case the data is erratic

╄→гoц情女王★ 提交于 2020-01-16 19:45:31
问题 So I'm having an issue in my React code. I have a parent component that renders a child component, which is a container with a few banner images. In the parent component (let's call it Parent ), I make an axios GET request to my API to fetch the data I need to pass as props to Child . I make this call inside the Parent 's componentDidMount() , which also houses some more separate axios calls. axios.get(`${config.host.api}/banners`).then(res => { let offban = res.data.trend; console.log(offban

How to assign headers in axios.all method React Native

坚强是说给别人听的谎言 提交于 2020-01-16 11:58:11
问题 I'm getting data from multiple api's and rendering into <Pickers /> but the issue is that I'm unable to assign headers for Auth in this axios.all method. Kindly provide me a solution or mistake if I'm doing. axios.all([ axios.get(this.apiUrl + '/case/GetCaseType'), axios.get(this.apiUrl + '/case/GetCasePriority') ], { headers: { 'authorization': 'bearer ' + this.state.jwtToken } }) .then(axios.spread(( response2, response3) => { console.log('Response 1: ', response1.data.retrn); console.log(

How to get req.query value from Node.js backend to React-Redux front-end?

浪尽此生 提交于 2020-01-16 08:50:30
问题 GOAL : to have a functioning query search on the react front end. TRIED : Backend looks like this //route: GET /shop //note: get all the products on shop page //access: public router.get('/', async (req, res) => { try { let items //sort by category if(!req.query.category) { items = await Product.find() } else { items = await Product.find({category: req.query.category}) } //sort by price and letter if(req.query.sortBy) { let sort ={} const sortByArray = req.query.sortBy.split(':') sort

Error 400 when making POST request to Spotify API with Axios on Express.js

走远了吗. 提交于 2020-01-15 08:57:06
问题 I'm trying to retrieve an access token from the Spotify API when making a post request with axios on an Express back end server. So far I have been unsuccessful. I'm getting the following error: data: { error: 'unsupported_grant_type', error_description: 'grant_type must be client_credentials, authorization_code or refresh_token' } } } I've already tried to change 'data' property for 'grant_type' to 'params' but it's still not working. Any advice would help. const express = require('express')

Always failed when POST data with json (body: raw)

☆樱花仙子☆ 提交于 2020-01-14 14:28:31
问题 I'm have trouble when send data to my server. I'm working with react native & axios ver ^0.16.2 let input = { 'longitude': -6.3922782, 'latitude': 106.8268856, 'content': 'uget - uget sampai kaki lemes', 'pictures': [] } axios({ method: 'POST', url, headers: { 'Content-Type': 'application/json', 'Authorization': this.state.headers.authorization }, data: input }) .then((resultAxios) => { console.log('hasil axios', resultAxios) }) and the status result always error 500. If I try send data with

NodeJS, Axios - post file from local server to another server

家住魔仙堡 提交于 2020-01-14 12:35:30
问题 I have an API endpoint that lets the client post their csv to our server then post it to someone else server. I have done our server part which save uploaded file to our server, but I can't get the other part done. I keep getting error { message: 'File not found', code: 400 } which may mean the file never reach the server. I'm using axios as an agent, does anyone know how to get this done? Thanks. // file = uploaded file const form_data = new FormData(); form_data.append("file", fs