0

I am building a travel website where for the search destinations option I am getting the following error:

Origin null is not allowed by Access-Control-Allow-Origin

My json file is in my folder itself, the following is my jquery code:

$(document).ready(function() {
            $.getJSON('resort.json', function(data) {
                $("#searchresort").on("click", function() {
                    var userDept = $("input:checked").val();
                    var output = "<ul>";
                    for (var i in resort.resorts) {
                        if( (userDept == resort.resorts[i].destination) || (userDept == "Any") ) {
                            output+="<li>" + resort.resorts[i].picture + "<br> " + resort.resorts[i].name + "<br>" + resort.resorts[i].short_description + "<br> " +"<a href='" + resort.resorts[i].id + ".html'>Visit Page</a></li>";


                            // " -- " + data.users[i].dept+"<a href='" + data.users[i].id + ".html'>Visit Page</a></li>";
                        }
                    }
                    output+="</ul>";
                    document.getElementById("placeholder").innerHTML = output;
                });

if anyone could help me out with this, it would be great.

Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
Harsh
  • 187
  • 2
  • 2
  • 7
  • You can't do that. You need a server. – SLaks Jan 11 '16 at 03:13
  • Possibly duplicate http://stackoverflow.com/questions/8456538/origin-null-is-not-allowed-by-access-control-allow-origin No research done before posting this question – brk Jan 11 '16 at 03:18

1 Answers1

0

Many browsers will not allow you to read files from a file:// origin. So, if your web page is loaded by the browser directly from the file system with a file:// URL, then you can't read other files with file:// URLs even though it seems like it should be the "same origin". This is apparently done for security reasons to avoid any possible ways for a web page to read files from your hard drive.

The browser reports file:// as a null origin in that error message.

Though not recommended, some browsers have a command line argument or other preference settings that will allow local files to be accessed, but this comes with the usual security warnings.

The usual solution here is to run a local web server and load your files via the web server rather than directly from the file system.

jfriend00
  • 683,504
  • 96
  • 985
  • 979