axios

React JS & Axios chaining promies

你离开我真会死。 提交于 2019-12-11 16:24:24
问题 I am developing a react js application and we are using a promise based library axios for calling APIs. Now, in the initial part of application, user gets a login page, when the login is successful, we contact different systems to retrieve some extra information about user. axios .get('url to authentication endpoint') // 1st call .then(response => { // if login is successful // 1. retrieve the user preferences like, on the customised screens what fields user wanted to see axios.get('user

Cannot do axios PUT request in Django REST+React framework - Error 403

浪子不回头ぞ 提交于 2019-12-11 16:16:14
问题 I can do GET requests via the following: axios.get('/by/f') .then(function (data) { this.setState({list: data.data}); }.bind(this)) .catch(function (error) { console.log(error); }); However, when I try a PUT request to update my django database, I get a 403 error: axios({ method: 'put', url: '/by/f', data: { item: item, frequency: frequency } }).then(function (response) { console.log(response); }); My view: class FrequencyList(APIView): def get(self, request, format=None): frequency =

How to scrape Javascript rendered websites using Javascript?

笑着哭i 提交于 2019-12-11 16:16:01
问题 I'm trying to scrape the $('a[href^="mailto:"]') of this website: https://celsius.network/ When I go to the browser console and run that, I get a link so I know it's there. The issue is that my request (using the Axios library) returns the DOM before javascript is loaded. I've set the User-Agent, but it looks like it's not working. const axiosClient = () => axios.create({ headers: { "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko)

CORS preflight request not handled by external API

谁说我不能喝 提交于 2019-12-11 16:10:00
问题 I'm trying to create front-end application for getresponse.com. It has own API which located at https://api.getresponse.com. When I'm trying to do any javascript request form browser with Axios or Fetch I've got this error: Access to XMLHttpRequest at 'https://api.getresponse.com/v3/accounts' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested

How to populate a Vuetify Select using data from axios

帅比萌擦擦* 提交于 2019-12-11 16:01:56
问题 I need to populate a Vuetify select, but there is a problem with it, my Get method returns data, but the vuetify select only show something like this: The text shows valid data: [ { "id": 1 }, { "id": 2 } ] And to populate the Select i follow the documentatioin adding :items="entidades" and :item-text="entidades.id" and :item-value="entidades.id" <v-select :items="entidades" :item-text="entidades.id" :item-value="entidades.id" single-line auto prepend-icon="group_work" label="Seleccionar

Axios data coming out to be undefined

与世无争的帅哥 提交于 2019-12-11 15:56:49
问题 I have a route in nodeJs which looks like this app.get("/", (req, res) => { console.log(req.user) res.json(req.user) }) Here console.log showing undefined but if I visit the address (localhost:3000/) it displays the following the data (in json) // 20181025193337 // http://localhost:3000/ { "isFormFilled": false, "_id": "5bd1a3d82101d36407f81218", "username": "Rohit Bhatia", "userId": "102775073203963169965", "image": "https://lh5.googleusercontent.com/-7HxFRQOCd9Q/AAAAAAAAAAI/AAAAAAAAAU8

How to use react stateless component when API response didn't got yet?

荒凉一梦 提交于 2019-12-11 15:50:47
问题 I'm working with react in Laravel, and i'm trying to built a simple FriendsList component to display data from API. The problem is that the Parent (Profile) component is finish loading before it's get the data, so the FriendsList component return an error, because the props are empty for the first time. It's important to say that regardless of the API response - the parent (Profile) component works well, it's loaded for the first time empty - and then the data is adding. The Api call export

Response from pre-flight failing with Status 405

99封情书 提交于 2019-12-11 15:39:37
问题 I'll start by saying I'm a bit of a newb when it comes to Javascript/React. I am attempting to communicate with my WCF endpoint server but I can’t seem to send any POST messages without getting a response: OPTIONS http://###/testbuyTicket 405 (Method Not Allowed) It seems that because I am sending it with content-type JSON it requires a ‘pre-flight’ and this is where it is failing. This is my client code: var headers = { 'headers': { 'Content-Type': 'application/json', } } axios.post(call,

Axios POST request only working sometimes (MERN app)

心已入冬 提交于 2019-12-11 15:36:45
问题 My axios POST request works about 70% of the time. There doesn't seem to be a pattern between which inputs work and which ones don't (length doesn't seem to matter). I've tried reading all of the stackoverflow questions with similar problems and nothing has worked. onSubmit() { const newInput = { input_text: this.state.value, } instance.post('http://localhost:4000/inputs/add/', newInput) .then(res => { console.log(res.data); }) .catch(error => { if (error.response) { console.log(error

why actual and expected length is not equal in react js

老子叫甜甜 提交于 2019-12-11 14:56:14
问题 could you please tell me why actual and expected length is not equal in react js here is my code https://codesandbox.io/s/oq7kwzrnj5 mockAxios.get.mockImplementation(() => Promise.resolve({ data: { data: ['a','b'] } })); I am sending 2 elements on array but getting 0 element it("axios call check or not", async () => { const wrapper = shallow(<List />); expect(mockAxios.get).toHaveBeenCalledTimes(1); expect(wrapper.find("li").length).toBe(2); }); 回答1: You are making async call in