I am facing an issue with loading multiple SVG files asynchronously. I have created a function to accomplish this:
function loadSVG(fileName){
var getSVG = new XMLHttpRequest();
getSVG.open('GET','assets/svg/'+fileName+'.svg',false);
getSVG.send();
return getSVG.responseXML.documentElement;
}
Using the function looks like this:
var baseSVG = loadSVG('base');
document.getElementById('canvas').appendChild(baseSVG);
Everything works fine with the first call, but when I try to load another SVG file, it fails. For example:
var midSVG = loadSVG('mid');
document.getElementById('canvas').appendChild(midSVG);
The error message I receive is:
'Uncaught TypeError: Property 'loadSVG' of object [object object] is not a function
As someone who isn't very experienced in javascript and ajax, I'm unsure why this issue is occurring.