fetch-api

Fetch api does not work in webextensions

让人想犯罪 __ 提交于 2019-12-23 21:26:17
问题 I'm experimenting firefox webextensions. I'd like to make HTTP requests using the fetch API after submitting a form. The problem is that the fetch request is not doing anything. Here is the data extracted from my manifest.json: "browser_action": { "default_popup": "test.html" }, "permissions": [ "<all_urls>" ], Here is my test.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <form> <button type="submit">Submit</button> </form> <script src="test.js"></script> </body> <

fetch resource, compute hash, return promise

折月煮酒 提交于 2019-12-23 09:56:46
问题 I would like to use the Fetch API in a browser extension to download a resource and compute a hash thereof. The following works (using crypto through Browserify) fetch(url).then(function(response) { return response.blob(); }).then(function(data) { var a = new FileReader(); a.readAsBinaryString(data); a.onloadend = function() { var hash = crypto.createHash(hashType); hash.update(a.result, 'binary'); return hash.digest('hex'); }; }) but has the disadvantage that I have to wait for a.onloadend

How to get Readable error response from javascript Fetch api?

本秂侑毒 提交于 2019-12-23 07:28:37
问题 I am working on Reactjs redux on front-end and Rails api as a back-end. So now i call api with Fetch api method but the problem is i cannot get readable error message like what i got inside the network tabs this is my function export function create_user(user,userInfoParams={}) { return function (dispatch) { dispatch(update_user(user)); return fetch(deafaultUrl + '/v1/users/', { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, method: "POST", body: JSON.stringify

POST request using fetch not working

旧城冷巷雨未停 提交于 2019-12-23 06:12:42
问题 I'm trying to do a post call from my react application using below code. writeToFile = (data = {}) => { let url = "http://localhost:8000/write"; console.log(data); return fetch(url, { method: 'post', headers: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: JSON.stringify({"content": "some content"}) }).then(res=>res.json()) .then(res => console.log(res)); } However, it gives me below given error: The same request is working in postman (API testing

POST request using fetch not working

大城市里の小女人 提交于 2019-12-23 06:12:40
问题 I'm trying to do a post call from my react application using below code. writeToFile = (data = {}) => { let url = "http://localhost:8000/write"; console.log(data); return fetch(url, { method: 'post', headers: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: JSON.stringify({"content": "some content"}) }).then(res=>res.json()) .then(res => console.log(res)); } However, it gives me below given error: The same request is working in postman (API testing

React Native fetch() not working

随声附和 提交于 2019-12-22 08:45:37
问题 I am trying to create a React Native app which fetches data from Google APIs but I am experiencing some issues (Unhandled JS Exception: undefined is not an object (evaluating 'responseData[0].destination_addresses') ). Here is the code: 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, TouchableHighlight, } = React; var INITIAL_DATA = [ {city: 'CityName', duration: "0 hours"}, ]; var REQUEST_URL = 'https://maps.googleapis.com/maps/api/distancematrix

Hook all Fetch Api AJAX requests

本小妞迷上赌 提交于 2019-12-22 04:16:12
问题 How would you hook all AJAX requests that use the Fetch Api? Previously we could do something like this to hook all XMLHttpRequest: (function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function() { console.log('request started!'); this.addEventListener('load', function() { console.log('request completed!'); console.log(this.readyState); //will always be 4 (ajax is completed successfully) console.log(this.responseText); //whatever the response was });

React Native fetch API cannot disable caching

空扰寡人 提交于 2019-12-22 01:43:43
问题 I am building android app using react native expo integrated with redux. The API is called using fetch method, but always the cached result is displayed. The server did not receive the request second time. I tried disabling cache with the following code. export const mymails = (token) => { return fetch( API_URL+'?random_number='+ new Date().getTime(), { method: 'GET', headers: getHeaders(token) }) .then(response => response.json()); }; getHeaders = (token) => { return { 'Accept': 'application

Fetch API not getting full HTML page

不羁岁月 提交于 2019-12-22 01:28:23
问题 I'm using the Fetch API to get some (public) data from a webpage. Here is my code: const proxyurl = "https://cors-anywhere.herokuapp.com/"; var bookUrl = "the+old+man+and+the+sea"; var url = 'https://miss.ent.sirsidynix.net/client/en_US/mlsathome/search/results?qu=' + bookUrl + '&te=ILS'; fetch(proxyurl + url).then(function(result){ return result.text(); }).then(function(text){ var parser = new DOMParser(); var html = parser.parseFromString(text, 'text/html'); var divs = html

What is the point of request.mode in the fetch API, especially with respect to cors?

左心房为你撑大大i 提交于 2019-12-21 19:43:30
问题 Looking at the new fetch API, you can specificy a mode field in the request. From Mozilla: The mode read-only property of the Request interface contains the mode of the request (e.g., cors, no-cors, same-origin, or navigate.) This is used to determine if cross-origin requests lead to valid responses, and which properties of the response are readable. And then how to use it: var myHeaders = new Headers(); var myInit = { method: 'GET', headers: myHeaders, mode: 'cors', cache: 'default' }; fetch