Get multiple SVG file contents using javascript/ajax function -
i have multiple svg files want load asynchronously. i've written following function can call:
function getsvg(filename){ getsvg = new xmlhttprequest(); getsvg.open('get','assets/svg/'+filename+'.svg',false); getsvg.send(); return getsvg.responsexml.documentelement; }
now can load contents so:
var basesvg = getsvg('base'); document.getelementbyid('canvas').appendchild(basesvg);
that works great, when try call second time doesn't work. example:
var midsvg = getsvg('mid'); document.getelementbyid('canvas').appendchild(midsvg);
this time following error:
'uncaught typeerror: property 'getsvg' of object [object object] not function
i'm no great expert javascript , ajax not sure about.
function getsvg(filename){ // <- create function in global namespace called getsvg var getsvg = new xmlhttprequest(); // <- overwrite function new xmlhttprequest object ... }
Comments
Post a Comment