Hybrid app : load file local

Không thể dùng fetch để load local được, vì vậy phải build 1 function mới

function fetchLocal(url) {
  return new Promise(function(resolve, reject) {
    var xhr = new XMLHttpRequest
    xhr.onload = function() {
      resolve(new Response(xhr.responseText, {status: xhr.status}))
    xhr.onerror = function() {
      reject(new TypeError('Local request failed'))
    xhr.open('GET', url)

Tham khảo

Cách 2: Chưa thử

var path = window.location.href.replace(‘index.html’, );
$.getJSON(path + “fixtures/initial.json”, function(data)
    // do something with data

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s