Reputation: 168
How can I get SVG file though ajax without any errors that could be manipulable (selectable) with javascript. When I try simple jQuery get function it looks like works but the problem is with putting content inside div.
when I try it with code like this
jQuery.get( "mysvg.svg", function( data ) {
console.log(data);
})
in console it shows full code, but if I try to put it in DOM I get
jquery.js?ver=1.12.4:2 Uncaught TypeError: Cannot read property 'ownerDocument' of null
How can I solve this problem?
Upvotes: 1
Views: 190
Reputation: 1187
Try setting the data type to "text" and then append to element.
jQuery.get( "mysvg.svg", null , function( data ) {
$('body').append(data);
},'text');
Upvotes: 0
Reputation: 168
The solution is taking a child array of #document object which is ["documentElement"]
So svg perefectly appends with this jQuery code
$.get( "mysvg.svg", function( data ) {
jQuery("#youdiv").append(data["documentElement"]);
})
Upvotes: 1