axios

axios IE promise doesn't work

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 05:05:48
问题 I am using axios for ajax communication. I have problem with IE. IE return error about Promise. IE doesn't know anything about Promise. I am writing react/redux but I tried axios in plain JS and same result Could someone help me with it? I am confused because axios should work on IE 8+ I tried on IE 11 (windows 10 64bit) My trial is written as is in example on axios homepage thx 回答1: You have to include a promise polyfill if the browser has no promise implementation. This sounds complicated

'Access-Control-Allow-Origin' issue when API call made from React (Isomorphic app)

你离开我真会死。 提交于 2019-12-18 04:32:25
问题 I'm running into an issue with my isomorphic JavaScript app using React and Express. I am trying to make an HTTP request with axios.get when my component mounts componentDidMount() { const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders'; axios.get(url).then( res => { //use res to update current state }) } I am getting a status 200 res from the API, but I am not getting any response data and getting an error in my console XMLHttpRequest cannot load http://ufc-data-api

How to use JSONP on fetch/axios cross-site requests

我是研究僧i 提交于 2019-12-18 03:38:42
问题 I'm trying to do a GET request on wikipedia API. Using jQuery as below works fine: $.ajax({ url: 'https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=Test&callback=JSON_CALLBACK', type: 'GET', headers: {'X-Requested-With': 'XMLHttpRequest'}, crossDomain: true, dataType: 'jsonp' }).done(function(data) { console.log("Data: ", data); }); But I want to

redux-promise with Axios, and how do deal with errors?

99封情书 提交于 2019-12-18 03:32:58
问题 So, I see on an error, redux-promise hands me back error: true, along with the payload, but that is once it hits the reducer... to me, decoupling the request AND error condition is a bit odd, and seems inappropriate. What is an effective way to also deal with error condition when using axios w/ reduc-promise (middleware).. here is the gist of what i have.. in action/ const request = axios(SOME_URL); return { type: GET_ME_STUFF, payload: request } in reducer/ const startState = { whatever: [],

how to get onUploadProgress in axios?

不想你离开。 提交于 2019-12-17 23:37:31
问题 I am little bit confused that how to upload progress evt with axios.Actually I am storing huge number files into aws s3.For that how to get uploaded progress I need this function onUploadProgress Currently my Post request is like this export function uploadtoCdnAndSaveToDb(data) { return dispatch => { dispatch(showUnderLoader(true)); return axios.post('/posttodb',{data:data}, ).then((response) => { console.log(response.data) }) } } 回答1: The Axios repository has a clear example on how to do

sending file and json in POST multipart/form-data request with axios

旧时模样 提交于 2019-12-17 22:19:14
问题 I am trying to send a file and some json in the same multipart POST request to my REST endpoint. The request is made directly from javascript using axios library as shown in the method below. doAjaxPost() { var formData = new FormData(); var file = document.querySelector('#file'); formData.append("file", file.files[0]); formData.append("document", documentJson); axios({ method: 'post', url: 'http://192.168.1.69:8080/api/files', data: formData, }) .then(function (response) { console.log

How to prevent Axios from encoding my request parameters?

▼魔方 西西 提交于 2019-12-17 19:33:57
问题 I'm trying to pass in an API key through the URL parameters in my GET request. However, I notice that Axios encodes the characters in my API key when sending the request. This causes the API to reject my request as it couldn't recognise my key. How can I prevent Axios from encoding my GET parameters? 回答1: You can use a custom param serializer as follows: axios.get('https://foobar.com/api', { paramsSerializer: function(params) { var result = ''; // Build the query string return result; } });

Sending the bearer token with axios

青春壹個敷衍的年華 提交于 2019-12-17 15:27:26
问题 In my react app i am using axios to perform the REST api requests. But it's unable to send the Authorization header with the request. Here is my code: tokenPayload() { let config = { headers: { 'Authorization': 'Bearer ' + validToken() } } Axios.post( 'http://localhost:8000/api/v1/get_token_payloads', config ) .then( ( response ) => { console.log( response ) } ) .catch() } Here the validToken() method would simply return the token from browser storage. All requests are having a 500 error

Cannot access correct this inside an axios callback [duplicate]

大城市里の小女人 提交于 2019-12-17 10:02:01
问题 This question already has answers here : How to access the correct `this` inside a callback? (10 answers) Closed 10 months ago . got a little mind-fart atm. I've managed to write following code, which downloads a JSON from url and displays it on the screen: export default class Appextends React.Component { constructor(props) { super(props); this.state = { data: [], } } componentWillMount() { axios.get(//url//) .then(function (response) { localStorage.setItem('data', JSON.stringify(response

How to send authorization header with axios

依然范特西╮ 提交于 2019-12-17 08:35:11
问题 How can I send an authentication header with a token via axios.js? I have tried a few things without success, for example: const header = `Authorization: Bearer ${token}`; return axios.get(URLConstants.USER_URL, { headers: { header } }); Gives me this error: XMLHttpRequest cannot load http://localhost:8000/accounts/user/. Request header field header is not allowed by Access-Control-Allow-Headers in preflight response. I have managed to get it work by setting global default, but I'm guessing