Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fetch(REQUEST_URL, {
- method: 'get',
- dataType: 'json',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- }
- })
- .then((response) =>
- {
- response.json() // << This is the problem
- })
- .then((responseData) => { // responseData = undefined
- console.log(responseData);
- });
- }).catch(function(err) {
- console.log(err);
- })
- .done();
- JSON.parse(response._bodyText)
- .then(response => response.json())
- .then(response => {
- console.log(response);
- var makeRequest = function(){
- fetch('https://jsonplaceholder.typicode.com/posts/1', {
- method: 'get',
- dataType: 'jsonp',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- }
- })
- .then((response) => {
- return response.json() // << This is the problem
- })
- .then((responseData) => { // responseData = undefined
- addTestToPage(responseData.title);
- return responseData;
- })
- .catch(function(err) {
- console.log(err);
- })
- }
- function addTestToPage(textToAdd){
- var para = document.createElement("p");
- var node = document.createTextNode(textToAdd);
- para.appendChild(node);
- var element = document.getElementsByTagName("body")[0];
- element.appendChild(para);
- }
- makeRequest();
- fetch('http://localhost:3001/questions', {
- method: 'GET',
- headers: {
- "Accept": "application/json",
- 'Content-Type': 'application/json'
- }
- })
- .then(response => { return response.json();})
- .then(responseData => {console.log(responseData); return responseData;})
- .then(data => {this.setState({"questions" : data});})
- .catch(err => {
- console.log("fetch error" + err);
- });
- }
- .then(response => {
- console.log(response.main);
- this.setState({
- weather: ((response.main.temp * (9/5))-459.67).toFixed(0),
- humidity:((response.main.humidity * (9/5))-459.67).toFixed(0)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement