Use XHR to load HTML templates
This commit is contained in:
parent
4fe13fab8e
commit
6086cedf2b
|
@ -533,13 +533,22 @@ $(document).ajaxError(function myErrorHandler(_, xhr) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getUrlSync(url, cache = true) {
|
/**
|
||||||
return $.ajax({
|
* Loads a URL content using XMLHttpRequest synchronously.
|
||||||
type: 'GET',
|
* @param {string} url URL to load synchronously
|
||||||
url: url,
|
* @returns {string} Response text
|
||||||
cache: cache,
|
*/
|
||||||
async: false,
|
function getUrlSync(url) {
|
||||||
}).responseText;
|
console.debug('Loading URL synchronously', url);
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.open('GET', url, false); // `false` makes the request synchronous
|
||||||
|
request.send();
|
||||||
|
|
||||||
|
if (request.status >= 200 && request.status < 300) {
|
||||||
|
return request.responseText;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Error loading ${url}: ${request.status} ${request.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const templateCache = new Map();
|
const templateCache = new Map();
|
||||||
|
|
Loading…
Reference in New Issue