1

During this pandemic, I've taken to playing games online with friends. We experimented recently with playing a specific card game long-distance, but it was a pain for my friend to have to draw and relay to me my hand. I created a very simple web app that simulates having the cards. I have all the functionality I need (draw hand, discard card, etc.), but I was hoping to input the cards via JSON rather than input them all in an array in the javascript file.

The JSON is formatted correctly (I checked with jsonlint), but I'm having trouble importing the JSON and putting it in my variable.

This is my current code for trying to load it in. I'm getting the error

Access to XMLHttpRequest at 'file location' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

$.getJSON("./assets/heroes.json", function(data) {
       game.allHeroes = data;
       console.log(game.allHeroes);
});

I'm going real bare bones with this project -- just HTML, CSS, Javascript, & JQuery. It's not intended to really be used by anybody but me, so I wasn't planning to upload it to Github or anything.

Celia
  • 7
  • 3
  • This is a security thing preventing js from accessing local files, If you use vs code there are some extensions you can use to set up a local "web server" that will host your site on localhost and allow you to access files from the folder containing your js/html – IrkenInvader May 06 '20 at 21:29

0 Answers0