axios

Can't display data after fetch

柔情痞子 提交于 2021-01-29 09:20:30
问题 I'm trying to get a data from an REST endpoint through axios and then render them in my app.js component and after that provide them to the whole app by using context API: axios.js import axios from 'axios'; const instance = axios.create({ baseURL: 'api_endpoint' }); export default instance; app.js import Context from './context' class App extends Component { constructor(props) { super(props) this.state = { comp: [] } }; async componentDidMount() { await instance.get('') .then(res => { const

React Native Deck Swiper

对着背影说爱祢 提交于 2021-01-29 09:17:23
问题 I am trying to make a GET request to an enpoint using the two functional components below to display in my react native deck swipper //using fetch const getDataUsingFetch = () => { fetch(latestNews+ApiKey) .then((response) => response.json()) .then((responseJson) => { // set the state of the output here console.log(responseJson); setLatestNews(responseJson); }) .catch((error) => { console.error(error); }); } //using anxios //asynchronous get request call to fetech latest news const

Alpine.js +flatpickr Datetimepicker is not working

谁说我不能喝 提交于 2021-01-29 09:09:16
问题 i really stucked in my project. I have a site with alpine.js where i want to render data to an element Everything is working perfect until the fact that my flatpickr is not shown up. The datepicker is working perfect. It seams, that x-html, x-text nor document.getElementById().innerHTML used in alpine.js is working .... <div x-data="app()" x-html="modalData" x-show="isOpenModal" id="test"> only a test <input class="picker" /> </div> ...... <script> const fp = flatpickr(".picker", { locale:

Axios POST isn't running inside NodeJS/Express Route

十年热恋 提交于 2021-01-29 08:55:45
问题 I'm calling my express route (domain.com/api) from another domain (domain1.com). So I've set up Express to accept POST requests to the route /api and signing a JWT before exchanging the JWT via Axios for a Bearer access token. I cannot seem to get the Axios post request to fire. Is is possible it's a firewall thing? How can I see where the error lives? Forgive me, I'm still new to Node/Express. Here is my pertinent code: const express = require('express'); const cors = require("cors"); const

Cheerio, axios, reactjs to web scrape a table off a webpage returning empty list

非 Y 不嫁゛ 提交于 2021-01-29 08:53:50
问题 Trying to scrape this table off this website: https://www.investing.com/commodities/real-time-futures But for some reason when I try to get the data, I keep getting an empty list. This is what I'm doing to get the data and parse it: componentDidMount() { axios.get(`https://www.investing.com/commodities/real-time-futures`) .then(response => { if(response.status === 200) { const html = response.data; const $ = cheerio.load(html); let data = []; $('#cross_rate_1 tr').each((i, elem) => { data

Req.body is empty when I POST using axios but when I use 'request' it's working fine

不羁的心 提交于 2021-01-29 08:21:02
问题 A little background - I have my NodeJS server running on port 3001 and my React application on port 3000. I've set up a proxy in my React application package.json to proxy all requests to port 3001 - "proxy": "http://localhost:3001" Now when I'm using Axios in my React application to make POST request on 'users/authentication' route on my NodeJS server, the request body is being parsed as blank on the Node server const request = { method: 'POST', url: `/users/authenticate`, headers: {

Axios not authenticating to API

戏子无情 提交于 2021-01-29 08:20:19
问题 Ive been trying all day to get data from my Asp.Net Api but with no avail. I login and get an authentication token from the server and store it locally but when I try to perform any action that requires authentication, the server returns a 401 response. Is there something Im doing wrong in my code? When I use a tool like postman, everything works okay but not in my app. This is my login try { response = await API.post(AuthUrl, credentials) if(response.status >= 200 || response.status <= 299){

How to use Laravel Passport access tokens

随声附和 提交于 2021-01-29 08:14:03
问题 First let me describe the problem I want to solve. I have a Laravel backend project that I want to tranform into an API, and it looked like Laravel Passport was perfect for this. Therefore, I installed Laravel Passport into my project. I have a client app which needs to use this API using axios. What I want to do is to make a post request with my username and password to the API to get an access token, and then use this access token to get or post relevant data. The access token is created by

TypeScript type of an async dispatch value

妖精的绣舞 提交于 2021-01-29 07:20:28
问题 I have the following async action definition: import {Dispatch} from 'react'; import axios, {AxiosResponse, AxiosError} from 'axios'; function asyncAction() { return (dispatch: Dispatch<any>): Promise<number> => { return axios.get('http://www.example.com') .then( (res: AxiosResponse<any>) => { return 1; }) .catch( (err: AxiosError<any>) => { return 2; }); } } The above typechecks fine. I also understand that when you call dispatch and pass it an asynchronous action, like so: dispatch

Updating state when dropdown select is changed React

醉酒当歌 提交于 2021-01-29 07:10:38
问题 This onChange event handles the selection of a dataschema then makes a subsequent request to get the queryschemas of the selected dataschema . handleChange is working correctly and renders the appropriate querySchemas in a dropdown list. handleChange = (e) => { const dataSchema = this.state.dataSchemas.find(dataSchema => dataSchema.name === e.target.value); if (dataSchema) { axios({ method: 'get', url: `${dataSchema.selfUri}/queryschemas/`, headers: { 'Accept': "" } }) .then(response => {