axios

How to upload FormData using Axios?

假装没事ソ 提交于 2019-12-21 21:32:36
问题 I am trying to upload 3 photos from frontend using formData. It will call an external API to make the upload. But encountered some errors as below. Frontend upload const formData = new FormData() formData.append('photoA', this.photoA) formData.append('photoB', this.photoB) formData.append('photoC', this.photoC) axios.post(`http://localhost:4172/uploadDocs`, { data: formData, accessToken: store.state.token }, { headers: { // 'Content-Type': 'Application/json', // 'x-access-token': localStorage

Axios - No 'Access-Control-Allow-Origin' header is present

走远了吗. 提交于 2019-12-21 11:00:29
问题 I'm missing something here. I was struggling to get the API call to work. Then I split the url up like below and it works -literally once. After that it fails to work again. I swear I did not change something. How do you go about it in AXIOS? Error message is: XMLHttpRequest cannot load http://magicseaweed.com/api/W2Z26fXscpELi7nPB0svfqcGj9FtGO9e/forecast/?spot_id=228. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not

Axios - No 'Access-Control-Allow-Origin' header is present

北战南征 提交于 2019-12-21 11:00:13
问题 I'm missing something here. I was struggling to get the API call to work. Then I split the url up like below and it works -literally once. After that it fails to work again. I swear I did not change something. How do you go about it in AXIOS? Error message is: XMLHttpRequest cannot load http://magicseaweed.com/api/W2Z26fXscpELi7nPB0svfqcGj9FtGO9e/forecast/?spot_id=228. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not

Axios Request Interceptor wait until ajax call finishes

可紊 提交于 2019-12-21 09:28:43
问题 I have an request interceptor for axios calls. It checks my jwt token and call for refresh if necessary. axios.interceptors.request.use((config) =>{ const state = store.getState(); // get renewed state const time = Math.floor( new Date().getTime() / 1000 ); if( ! state.app.jwtRefreshOnRequest && time >= state.jwt.expires - 120 && state.jwt.refresh_before > time ){ // expiring in 2 min. refresh //dispatch({type: 'JWT_REFRESH_REQUEST'}); axios.get( API_BASE_URL + '/auth/refresh') .then(function

Axios Request Interceptor wait until ajax call finishes

不问归期 提交于 2019-12-21 09:28:04
问题 I have an request interceptor for axios calls. It checks my jwt token and call for refresh if necessary. axios.interceptors.request.use((config) =>{ const state = store.getState(); // get renewed state const time = Math.floor( new Date().getTime() / 1000 ); if( ! state.app.jwtRefreshOnRequest && time >= state.jwt.expires - 120 && state.jwt.refresh_before > time ){ // expiring in 2 min. refresh //dispatch({type: 'JWT_REFRESH_REQUEST'}); axios.get( API_BASE_URL + '/auth/refresh') .then(function

How does one set global headers in axios?

吃可爱长大的小学妹 提交于 2019-12-21 06:59:30
问题 Hi I'm setting default axios headers in request interceptor but these headers are not accessible in another function... in axios axios documentation it is mentioned that global-axios-defaults are global...below is my sample code need help axios.interceptors.request.use(function (config) { axios.defaults.headers.accesstoken= "some_access_token" axios.defaults.headers.client = "some_client" axios.defaults.headers.uid = "some_uid" return config; },function (error) { return Promise.reject(error);

Axios Post Form with Reactjs

♀尐吖头ヾ 提交于 2019-12-21 06:24:39
问题 So I have this post method with Axios and if I submit this, it said Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:87) If I use this method: axios.post('http://localhost:5000/users', ({userid: this.state.userid}) it works. But if I add 2 or more arg to the axios post it gets error again: axios.post('http://localhost:5000/users', ({userid: this.state.userid}, {fullname: this.state.fullname} )) Here is my full code. As you can

axios http always returns with empty data

白昼怎懂夜的黑 提交于 2019-12-21 06:08:29
问题 I asked this question before and wasn't able to get an answer. I was able to do use method: 'get' like below to get it working so it was okay but this time I need to use post. In a different project (using react, redux, php, webpack, xampp) the same issue has resurfaced and I am trying to figure it out. So here it is: register.php echo $_GET['task']; index.js const values = {task: 'doSomething', username: 'username'} axios({ url: "./server/register.php", timeout: 20000, method: 'get', params:

axios http always returns with empty data

醉酒当歌 提交于 2019-12-21 06:07:14
问题 I asked this question before and wasn't able to get an answer. I was able to do use method: 'get' like below to get it working so it was okay but this time I need to use post. In a different project (using react, redux, php, webpack, xampp) the same issue has resurfaced and I am trying to figure it out. So here it is: register.php echo $_GET['task']; index.js const values = {task: 'doSomething', username: 'username'} axios({ url: "./server/register.php", timeout: 20000, method: 'get', params:

Vue.js: Uncaught promises in vuex actions

僤鯓⒐⒋嵵緔 提交于 2019-12-21 05:21:36
问题 I understand vuex actions return promises, but I haven't found the ideal pattern to handle errors in vuex. My current approach is to use an error interceptor on my axios plugin, then committing the error to my vuex store. in plugins/axios.js : export default function({ $axios, store }) { $axios.onError(error => { store.dispatch('setError', error.response.data.code); }); } in store/index.js : export const state = () => ({ error: null, }); export const mutations = { SET_ERROR(state, payload) {