1

I am trying to access the contents of an SVG file using jQuery AJAX but keep getting the same error in Chrome.

JavaScript

$.get("my.svg", function(data){
  print(data)
})

Console Output

[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

James Jensen
  • 518
  • 6
  • 19

2 Answers2

2

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.

James Jensen
  • 518
  • 6
  • 19
-1
$.get('/my.svg', function(svg) {
   console.log(svg);
}, 'text');
xlm
  • 6,854
  • 14
  • 53
  • 55
abhishek khandait
  • 1,990
  • 2
  • 15
  • 18