I'm loading an SVG using an XMLHttpRequest but I don't seem to be able to parse it. Here's how I'm loading it
var svgDoc;
var xhr = new XMLHttpRequest();
xhr.open("GET", "data/vectors.svg", true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
svgDoc = xhr.responseText;
console.log(svgDoc.getElementsByTagName("svg"));
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
It's throwing Uncaught TypeError: undefined is not a function. When I try console.log(svgDoc.getElementsByTagName) I just get 'undefined'. It's like I can't call any of the XML DOM methods on the SVG - despite the fact that SVG is just XML. Why is this?
No comments:
Post a Comment