Skip to content

enimax-anime/cordova-plugin-xhr-local-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-xhr-local-file

This plugin is a polyfill for XmlHTTPRequest that will handle the file:// protocol correctly using Cordova's File API behind the scenes.

Installation

$ cordova plugin add cordova-plugin-xhr-local-file
$ cordova prepare

Usage

You may now make XHR requests to local files. Moreover, other JS libraries that load assets via XHR will now function normally even when loading assets from your Cordova app's filesystem.

Since Cordova apps are loaded from file://, every relative URL uses the file:// protocol. This library resolves relative and absolute URLs using the Cordova www folder as the webroot.

var oReq = new XMLHttpRequest()
oReq.open('GET', './foo.json') // If you are in ./www/index.html, this resolves to ./www/foo.json
oReq.send()
var oReq = new XMLHttpRequest()
oReq.open('GET', '/foo.json') // If you are in ./www/index.html, this ralso esolves to ./www/foo.json
oReq.send()

cdvfile:// protocol is also honored:

var oReq = new XMLHttpRequest()
oReq.open('GET', 'cdvfile://localhost/bundle/www/data/foo.json')
oReq.send()

Thanks

Thanks to Oracle for their XHR polyfill implementation, upon which this one is based.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published