$("#container").load("test.svg");
function loadFile(url, id) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.send();
request.onreadystatechange = function() {
if (this.readyState != 4) return;
if (this.status != 200) {
console.log('Ошибка: ' + (this.status ? this.statusText : 'запрос не удался'));
return;
}
document.getElementById(id).innerHTML = this.responseXML;
}
}
loadFile("test.svg", "container");
$("#container").load( "test.svg", function() {
console.log( "This is callback function" );
});
function loadFile(url, id, callback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.send();
request.onreadystatechange = function() {
if (this.readyState != 4) return;
if (this.status != 200) {
console.log('Ошибка: ' + (this.status ? this.statusText : 'запрос не удался'));
return;
}
document.getElementById(id).innerHTML = this.responseXML;
callback();
}
}
function loadFile(url, id, callback) {
// Код запроса
request.onload = (event) => {
callback()
}
}
function load(src, selector, callback) {
fetch(src)
.then(response => response.text())
.then(svg => {
let elements = Array.from(document.querySelectorAll(selector))
elements.map(n => n.innerHTML = svg)
callback()
});
}