0

I am trying to load a json file into a table, after doing a lot of research I found solutions on how to do it.

But I am getting the below error on Chrome

XMLHttpRequest cannot load ... Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Please suggest how I can avoid this error while loading my json data in chrome.

  <script type="text/javascript">
 $(function() {
 $.getJSON('./files.json')
  .success(function(data) {
     var tr;
     for (var i = 0; i < data.length; i++) {
        tr = $('<tr/>');
        tr.append("<td>" + data[i][0] + "</td>");
        tr.append("<td>" + data[i][1] + "</td>");
        $('#table1').append(tr);
    }
})
.error(function(e) { console.error(e); })
});
</script>

Here is the HTML that I am loading the data into Name Path

1 Answer 1

2

The error message spells it out:

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

You can't use file URIs here since they aren't listed in the error message.

Install a web server and use http instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.