0

I am trying to figure out what is wrong with the function load() not working in Chrome and Firefox. Using Internet Explorer it works beautifully.

I have a WampServer.

In Chrome, I get error:

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

I put files on local server, it is on-line. I can access an image, see code. But what goes wrong with load()?

<body>
    here is a image
    <img src="/wamp/www/testing/baby2.jpg" width="100px" height="200px"></img>   

    <ul id="aj">
        <li><a href="/wamp/www/testing/celeb1.html">One</a></li>
        <li><a href="/wamp/www/testing/celeb2.html">Two</a></li>
        <li><a href="/wamp/www/testing/celeb3.html">Three</a></li>
    </ul>
    <br>
    <div id="desc">

    </div>

    <script>
    $(document).ready(function(){
        $('#aj a').click(function(){
            var v= $(this).attr('href');

            $('#desc').load(v);
            return false;
        });
    });//ready
    </script>
</body>

Thanks in advance.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • That means Chrome (and probably Firefox) thinks you are making a cross-domain request. This should not be the case if you load the page via your server but maybe you are loading the file directly? The code by itself is correct. – Felix Kling Jul 29 '12 at 09:42
  • Look at your URL in the address bar. If it starts with `file://` then the same-origin policy will restrict access to other files. Firefox will not allow you fetch files outside of that page's directory ([link](https://developer.mozilla.org/En/Same-origin_policy_for_file:_URIs)), and Chrome will not allow any access at all ([link](https://code.google.com/p/chromium/issues/detail?id=40787)). Also, if the page URL starts with `file://`, you are not accessing your files through your web server, which would be done via `http://`. – apsillers Jul 29 '12 at 22:08

3 Answers3

1

I think the problem in URL

try to write them like ....

     <ul id="aj">
       <li><a href="/testing/celeb1.html">One</a></li>
       <li><a href="/testing/celeb2.html">Two</a></li>
       <li><a href="/testing/celeb3.html">Three</a></li>
    </ul>

You can also take a look @ this Topic

Community
  • 1
  • 1
Sameh Serag
  • 747
  • 1
  • 8
  • 22
1

This is a problem with Chrome: see this bug and also this answer.

You may need to start Chrome using a special command line flag:

chrome.exe --allow-file-access-from-files
Community
  • 1
  • 1
jsshah
  • 1,741
  • 1
  • 10
  • 18
0

In your Apache settings (go to the file named httpd.conf in your WAMP installation), what are you specifying for your Home Directory? This is what your browser will go to when you use links which start with a forward slash, such as /testing/celeb1.html.

Normally, it'll be something like /wamp/www/. Because of this, you then only ever have to use the /testing/... part of the URI for hyperlinks.

hohner
  • 11,498
  • 8
  • 49
  • 84