fetch

Can't access fetch post data in controller: Codeigniter

孤街醉人 提交于 2021-01-27 20:28:15
问题 I'm making a post request using fetch in my codeigniter project. The request looks like this fetch('myurl/mycontroller', { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ testdata: 123, }) }).then((res) => { console.log(res); }).catch(console.log); My controller looks like below class MyController extends CI_Controller { public function mycontroller() { $data = $this->input->post('testdata'); return $data . " is the passed data."; } } But the data isn't

A problem with a post method (using fetch and express)

£可爱£侵袭症+ 提交于 2021-01-27 18:39:43
问题 I'm a very beginner so I hope my question is not that stupid. What I want to do is to pass a longitude and a latitude from a client-side javascript into a node.js on a server-side. I'm using a fetch and express.js. Below my html code: <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> </head> <body> latitude: <span id="latitude"></span>°<br /> longitude: <span id="longitude"><

Cannot read property 'map' of undefined, why?

自作多情 提交于 2021-01-27 18:22:59
问题 This is my App.js file. I am trying to fetch data using fetch() What am I missing? Getting Error as TypeError: Cannot read property map of undefined". What is wrong? How do I get the result? I'm following the reactjs tutorial, and I keep running into an issue when passing the value from the state of one component into another component. The error 'Cannot read property 'map' of undefined' is thrown when the map function in the CommentList component is executed. What would cause the prop to

Pass payload in GET request React fetch

旧时模样 提交于 2021-01-27 14:19:51
问题 I'm trying to build a react/node application and I was trying to pass a value which I get from user input to the nodejs api to call a separate api (Instagram API) I want to attach an object to req.body from React app. I want to do something like this: app.get('/hashtags', (req,res) => { console.log(req.body); console.log(req.body.tag); }); This is my responsible react app code for the above node request: handleChange(e){ const searchtag = 'hello'; fetch('/hashtags', { method: 'GET', headers:

testing fetch with mocha and chai

≯℡__Kan透↙ 提交于 2021-01-23 06:50:27
问题 I have the following example test: import { assert } from 'chai' function starWarsMovies () { fetch('http://swapi.co/api/films/') .then((res) => { return res.json() }) .then((res) => res.count) } describe('Get star war movies', () => { it('should get 7', () =>{ assert.equal(starWarsMovies(), 7) }) }) But I getting ReferenceError: fetch is not defined What do I have to use in order to test a fetch request. UPDATE I also tried: import { polyfill } from 'es6-promise' import fetch from

getting Fetch response data

依然范特西╮ 提交于 2021-01-15 06:40:47
问题 I'm using the chrome devTools to mirror a webRequest. Looking at the network request, there is some JSON data in the response that I want to get access to Right click --> Copy as fetch --> fetch( "https://www.url.com/service.svc?action=FindConversation&ID=-40&AC=1", { "credentials":"include", "headers":{ "accept":"*/*", "accept-language":"en-US,en;q=0.9", "action":"FindConversation", "content-type":"application/json; charset=UTF-8", "actionid":"-40", "unique_identifier":

getting Fetch response data

耗尽温柔 提交于 2021-01-15 06:32:15
问题 I'm using the chrome devTools to mirror a webRequest. Looking at the network request, there is some JSON data in the response that I want to get access to Right click --> Copy as fetch --> fetch( "https://www.url.com/service.svc?action=FindConversation&ID=-40&AC=1", { "credentials":"include", "headers":{ "accept":"*/*", "accept-language":"en-US,en;q=0.9", "action":"FindConversation", "content-type":"application/json; charset=UTF-8", "actionid":"-40", "unique_identifier":

'Access to fetch has been blocked by CORS policy' Chrome extension error

风格不统一 提交于 2021-01-07 03:13:15
问题 I know this has been asked many times, but it seems to me that I've done all the right things and still can't get it working. I am trying to get data from an external API from the background script of my Chrome extension, using messaging to initiate the call from the content script and get the results. I have no control over the external API. The documentation from that API says to use script tags to get a jsonp response, but if I understand correctly, that shouldn't matter when the below

'Access to fetch has been blocked by CORS policy' Chrome extension error

断了今生、忘了曾经 提交于 2021-01-07 03:12:34
问题 I know this has been asked many times, but it seems to me that I've done all the right things and still can't get it working. I am trying to get data from an external API from the background script of my Chrome extension, using messaging to initiate the call from the content script and get the results. I have no control over the external API. The documentation from that API says to use script tags to get a jsonp response, but if I understand correctly, that shouldn't matter when the below

Fetching data with axios in react

回眸只為那壹抹淺笑 提交于 2021-01-07 02:34:14
问题 I'm new in react so I'm trying to make a get request with axios in react with a service to get a track and the respective races from it, but I got track like a empty object. I need to know how to make the get request efficiently. trackUtils.js import AppDispatcher from '../dispatcher/AppDispatcher'; import ActionTypes from '../constants/AppConstants'; import config from '../../config'; import axios from 'axios'; class trackUtil { constructor() { this.serverConfig = config.ServiceConfig; this