0

The scenerio is as follows:

I have a simple jquery function which loads in a URL (the file to be loaded is located in the same directory as the file that it is being called from).

ie I am on http://www.example.com/page1.php

Within this page, I am calling a dialog that points to https://www.example.com/page2.php.

Code follows:

 $d("body").on('click','.myLink',function(){
  var url = $d(this).attr('href');
        $d("#mydialog").load(url).dialog('open');         
        return false;
    });

I get this error: XMLHttpRequest cannot load https://www.example.com/page2.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.example.com/page1.php' is therefore not allowed access.

NOTE - that the code is on the same domain in the same directory. I am not calling the script from an external domain.

How can I overcome this error?

Thanks very much in advance.

jagku
  • 309
  • 3
  • 14
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Dez Oct 12 '16 at 15:04
  • Because protocol is different it is considered a cross domain request and subject to CORS. Why are you mixing protocols? – charlietfl Oct 12 '16 at 15:14
  • As I have been asked to make 1 page https - out of the entire site. All pages have a navigation bar. When clicking on each item in the nav bar, a http page was traditionally called. Now, to avoid issues on the https page, we call all items using https. This is now causing all these pages on every single page of the site to fail to load with this error. I am not allowed to make the entire site https. – jagku Oct 12 '16 at 15:21
  • Add CORS headers to page2.php – Musa Oct 12 '16 at 15:57
  • Use `this.href`, not `$d(this).attr('href')`. It's a native property. – Walf Oct 12 '16 at 21:32
  • Sorry, I was being a bit thick! The problem was with the .htaccess (usual issue of thinking too deep about it and not stepping back!). Thanks for your help. – jagku Oct 13 '16 at 08:49

0 Answers0