fetch-api

How to search from API based on text inputs in REACT

穿精又带淫゛_ 提交于 2019-12-11 07:08:25
问题 when i search from API based on keyword,i get all details in API. i need get only details based on the text input from search.. i dont know the problem is in my API or My code... please help me.. import React, { Component } from 'react'; class Search extends Component { constructor(props) { super(props); this.state={ value:'', value2:'' }; this.handleChange=this.handleChange.bind(this); this.crimeChange=this.crimeChange.bind(this); this.search=this.search.bind(this); } handleChange(event){

Fetch API inside Service Worker fails only for the home page. When reloading it serves the cached offline page

随声附和 提交于 2019-12-11 06:56:24
问题 I've been fighting with this for a few months now and cannot figure it out. I've been using a service worker for a while now without issue but recently I would load my website's homepage and then do a simple refresh and I would be served the offline page (and if I remove the offline page from the cache it refreshes to connection error screen). This only happens on the home page and must have something to do with the Fetch API (see below). The fetch error is simply "Failed to fetch" and does

401 error - JWT Token not found using fetch

孤人 提交于 2019-12-11 06:19:25
问题 I am new to react, and mostly to javascript. I am using react for a web app hosted on localhost:3000 with node.js and symfony 2.8 for my back end, hosted on localhost:80 with apache, that exposes an api secured with lexik and fos user. Before securing the api, everything works fine. After securing the api, I get a 401 error when using fetch as follow: let myToken = localStorage.getItem('auth_token') //token properly retrieved let myHeaders = new Headers(); myHeaders.append("Authorization",

Shoutem fetch data not displaying

 ̄綄美尐妖づ 提交于 2019-12-11 05:27:43
问题 First I want to start by saying I am a total noob at React Native and Shoutem. I am not sure if I should write Shoutem or React Native in the subject of my questions, but here is my problem. I have two screens: Screen1.js Screen2.js Screen1 displays a list of items returned from a fetch. Once I click on the item, it will open the second screen which is the details screen. I am passing data from screen1 to screen2. In screen2 I need to make another fetch call for different data, but it does

Accessing response headers on CORS request

回眸只為那壹抹淺笑 提交于 2019-12-11 04:39:46
问题 I'm using the fetch API to make a cross-domain request similar to the below snippet window.fetch('http://data.test.wikibus.org/magazines', { method: 'get'}) .then(function(response) { var linkHeader = response.headers.get('Link'); document.querySelector('#link-header').innerText = 'The Link header is: ' + linkHeader; }); <span id="link-header"></span> As you see the Link header (and some other headers too) is not accessible although it is returned in the response. I assume that's a CORS issue

Change a jquery ajax POST request into a fetch api POST

孤者浪人 提交于 2019-12-11 02:49:50
问题 I have some json data that I have been posting to an API using $.ajax but I would like to update this to use the fetch API. However I seem to have it setup the Fetch API request ends up returning a 403 so I must be missing something but I can't work it out. Ajax request: $.ajax({ type: 'POST', url: url, data: { 'title': data.title, 'body': data.body, 'csrfmiddlewaretoken': csrf_token, 'request_json': true }, success: function (data) { console.log(data) } }); Fetch attempt (one of many): let

How can I construct a POST request body in React Native not with a stringified json but a json?

孤者浪人 提交于 2019-12-11 00:34:30
问题 I working on replace some native-code with react native. The expected POST request (implemented in AFNetworking ) in Charles should be like this: Code snippet: NSError *err; NSData *paramData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&err]; NSData *paramData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&err]; NSString *paramString = [[NSString alloc] initWithData:paramData encoding

fetch Promise never gets executed

梦想的初衷 提交于 2019-12-10 19:26:35
问题 I am using the nativescript to develop an app for android. I have something like var fetchModule = require("fetch"); fetchModule.fetch("http://202.120.227.11/") .then(function(resp){ console.log(JSON.stringify(resp)); return resp; }) .catch(function(err){ console.log(JSON.stringify(err)); return err; }); but the then block never gets executed. And sometimes the catch block gets executed and give a network error. But in either case, the request is sent and the response is smoothly received

Why does logging the result of fetch() “break” it (“body stream is locked”)?

无人久伴 提交于 2019-12-10 16:00:02
问题 In trying to understand a return result, I ended up with this simple thing: fetch('http://localhost:8081/position', {mode: 'cors'}) .then(response => {return response.json()}) .then(result => console.log(result)); which works - it prints the json of the response. But this does not work: fetch('http://localhost:8081/position', {mode: 'cors'}) .then(response => {console.log(response.json()); return response.json();}) .then(result => console.log(result)); It thows Uncaught (in promise) TypeError

How to convert Ajax to Fetch API in JavaScript?

折月煮酒 提交于 2019-12-10 15:49:10
问题 So I am using the JavaScript port of RiveScript which uses ajax and of course I don't want to use jQuery anymore. There is only one line ajax and I want to change it to the new Fetch API. **FYI: You can see the ajax code in line 1795 of the CDN.** So here's the original code: return $.ajax({ url: file, dataType: "text", success: (function(_this) { return function(data, textStatus, xhr) { _this.say("Loading file " + file + " complete."); _this.parse(file, data, onError); delete _this._pending