Created
          October 30, 2015 10:54 
        
      - 
      
 - 
        
Save rudin/0088021177007e2216ef to your computer and use it in GitHub Desktop.  
    Load a local json in your Cordova app
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Add to app .plst | |
| <key>NSAppTransportSecurity</key> | |
| <dict> | |
| <key>NSAllowsArbitraryLoads</key> | |
| <true/> | |
| </dict> | |
| var getJSON = function(url) { | |
| return new Promise(function(resolve, reject) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('get', url, true); | |
| xhr.responseType = 'json'; | |
| xhr.onload = function() { | |
| var status = xhr.status; | |
| if (status == 200 || status == 0) { | |
| resolve(xhr.response); | |
| } else { | |
| reject(status); | |
| } | |
| }; | |
| xhr.send(); | |
| }); | |
| }; | |
| loadData = function (callbackFN) { | |
| getJSON('assets/data.json').then(function(data) { | |
| callbackFN(data); | |
| }, function(status) { | |
| console.log('Something went wrong.'); | |
| }); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment