So I'm trying to download an svg using AJAX get request. But I'm having some errors:
The log:
In my html, this is what I'm trying to do:
Two problems here:
1. There is an error with the request.
2. In loadCanvas function, I'm trying to see if I can get the svg and manipulate the image(changing the color of particular elements). I can add svg element to html but it's too big and really effects the performance. Anyone tried this before?
The log:
Tue Sep 6 18:05:16 2016: loading AJAX request: https://test.com/svgFile
Tue Sep 6 18:05:16 2016: debug: [prefetch-1] loading https://test.com/svgFile
Tue Sep 6 18:05:17 2016: debug: [prefetch-1] loaded https://test.com/svgFile
Tue Sep 6 18:05:17 2016: debug: loaded resource: https://test.com/svgFile
Tue Sep 6 18:05:17 2016: debug: loaded resource: type: yes(resource_type("image/svg+xml", [], svg, no))
Tue Sep 6 18:05:18 2016: error: TypeError: invalid this value
In my html, this is what I'm trying to do:
<script>
function loadCanvas(dataURL) {
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
// load image from data url
var imageObj = new Image();
imageObj.onload = function() {
context.drawImage(this, 0, 0);
};
imageObj.src = dataURL;
}
// make ajax call to get image data url
var request = new XMLHttpRequest();
request.open('GET', 'https://test.com/svgFile', no);
request.send();
loadCanvas(request.responseText);
</script>
Two problems here:
1. There is an error with the request.
2. In loadCanvas function, I'm trying to see if I can get the svg and manipulate the image(changing the color of particular elements). I can add svg element to html but it's too big and really effects the performance. Anyone tried this before?