Advertisement
sorskoot

Fetch sample

Jun 7th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     "use strict";
  3.  
  4.     document.addEventListener('deviceready', onDeviceReady.bind(this), false);
  5.  
  6.     function onDeviceReady() {
  7.         getData()
  8.             .then(f=>console.log(f),
  9.                   e=>console.log(e.message));
  10.     };
  11.  
  12.     function getData() {
  13.         return new Promise((resolve, reject) => {
  14.             fetch('./data/somedata.json')
  15.                 .then(function (response) {
  16.                     return response.json().then(function (json) {
  17.                         resolve(json);
  18.                     }).catch(e=>reject(e));
  19.                 }).catch(e=>reject(e));
  20.         });
  21.     }
  22. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement