Reputation: 558
I am trying to access the contents of an SVG file using jQuery AJAX but keep getting the same error in Chrome.
$.get("my.svg", function(data){
print(data)
})
[Error] jquery.min.js:4 XMLHttpRequest cannot load file:'///Users/james.jensen/Desktop/helloworld/my.svg'. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
I literally copied and pasted the code from here and changed it to fit my situation, so I am unsure why my code is malfunctioning in this way.
Thanks in advance
Upvotes: 1
Views: 4096
Reputation: 558
It turns out that this issue is, in fact, Chrome related. I ran the same code on Safari and it worked perfectly. I looked into solutions that would enable me to run the same code on Chrome and discovered that I would have to run a server locally.
Upvotes: 2
Reputation: 2157
$.get('/my.svg', function(svg) {
console.log(svg);
}, 'text');
Upvotes: -1