An entry from the gengns log, written by Génesis García Morilla · · HTML5, JavaScript
Get local html files (views/widgets) and insert them into your Cordova Single Page Application
Approach to load different views into an Android SPA.
An index.html file with all the scripts, styles and so on.
HTML, CSS and JS files at least as many as views in folders called view, css and js respectively and with the same names to not mess around. Ex: page.html, page.css and page.js
We can use Axios to load views instead of the typical XMLHttpRequest that follows:
get_html_file.js
/**
Get local html files (views/widgets) to insert into your SPA
@param path ex:
path = 'file:///android_asset/www/view/page.html'
@param success
@param failure
*/
function get_html_file(path, success, failure) {
const xhr = new XMLHttpRequest()
xhr.open('GET', path)
xhr.onload = () => {
if (xhr.status == 200)
success(xhr.response)
else if (failure)
failure(xhr.status)
}
xhr.send()
}