2

I have used jQuery ajax in my html pages.

$.ajax({
    url: 'search/' + page + '.html',
    dataType: 'text',
    success: function(data) {
        $(".searchData").html(data);
        $(".searchData").show("slow");
        $(".searchImage").hide("slow");
    },
    error: function() {
        $(".searchImage").show("slow");
        $(".searchData").hide("slow");
    }
});

There is no server. I am accessing my page like file:///C:/Documents%20and%20Settings/sss/Desktop/rrr/search.html and it works fine in Firefox, but it's not working in Chrome and other browsers, it shows:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

How to do that?

Soumitra
  • 185
  • 5
  • 10
  • @PranavRam What do you think the OP has? lol – epascarello Jan 28 '14 at 18:12
  • 1
    possible duplicate of [My XML file is not being by Google Chrome and Internet Explorer](http://stackoverflow.com/questions/10038256/my-xml-file-is-not-being-by-google-chrome-and-internet-explorer) or [Chrome: Disable same origin policy](http://stackoverflow.com/q/3102819/1048572) – Bergi Jan 28 '14 at 18:45

1 Answers1

4

Because the browser has security measures to prevent it. If you want to work with the file system, you need to set up the browser to allow it.

How to launch html using Chrome at "--allow-file-access-from-files" mode?

Community
  • 1
  • 1
epascarello
  • 185,306
  • 18
  • 175
  • 214