daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetch(REQUEST_URL, {
  2.       method: 'get',
  3.       dataType: 'json',
  4.       headers: {
  5.         'Accept': 'application/json',
  6.         'Content-Type': 'application/json'
  7.       }
  8.     })
  9.     .then((response) =>
  10.       {
  11.         response.json() // << This is the problem
  12.       })
  13.     .then((responseData) => { // responseData = undefined
  14.  
  15.         console.log(responseData);
  16.      });
  17.      }).catch(function(err) {
  18.         console.log(err);
  19.       })
  20.      .done();
  21.    
  22. JSON.parse(response._bodyText)
  23.    
  24. .then(response => response.json())
  25.     .then(response => {
  26.  
  27.     console.log(response);
  28.    
  29. var makeRequest = function(){
  30.  
  31.     fetch('https://jsonplaceholder.typicode.com/posts/1', {
  32.         method: 'get',
  33.         dataType: 'jsonp',
  34.         headers: {
  35.            'Accept': 'application/json',
  36.            'Content-Type': 'application/json'
  37.         }
  38.     })
  39.     .then((response) => {
  40.        return response.json() // << This is the problem
  41.     })
  42.     .then((responseData) => { // responseData = undefined
  43.         addTestToPage(responseData.title);
  44.         return responseData;
  45.     })
  46.   .catch(function(err) {
  47.       console.log(err);
  48.   })
  49. }
  50.  
  51. function addTestToPage(textToAdd){
  52.    var para = document.createElement("p");
  53.    var node = document.createTextNode(textToAdd);
  54.    para.appendChild(node);
  55.  
  56.   var element = document.getElementsByTagName("body")[0];
  57.   element.appendChild(para);
  58. }
  59.  
  60. makeRequest();
  61.    
  62. fetch('http://localhost:3001/questions', {
  63.         method: 'GET',
  64.         headers: {
  65.         "Accept": "application/json",
  66.         'Content-Type': 'application/json'
  67.         }
  68.     })
  69.     .then(response => { return response.json();})
  70.     .then(responseData => {console.log(responseData); return responseData;})
  71.     .then(data => {this.setState({"questions" : data});})
  72.  
  73.     .catch(err => {
  74.         console.log("fetch error" + err);
  75.     });
  76. }
  77.    
  78. .then(response => {
  79.  console.log(response.main);
  80.  this.setState({
  81.    weather: ((response.main.temp * (9/5))-459.67).toFixed(0),
  82.    humidity:((response.main.humidity * (9/5))-459.67).toFixed(0)
  83.  })
RAW Paste Data
Top