2

I've read about origin policy etc and as I understand it you should put origin policiy domain on the client and on the server.

Ok lets say I have this code on example.com and I want to fetch info from the page doyouknoweverything.doyouknoweverything.com/recordOfMyLife with jQuery/ajax

<div id="sk">Loading...</div> 
<script>
document.domain = "{example.com}";
$( "#sk" ).load( "http://whatever.doyouknoweverything.com/recordOfMyLife" );
</script>

If I understand this correctly I can do like this in the php-file whatever.doyouknoweverything.com/recordOfMyLife:

header("Access-Control-Allow-Origin: *");

Is this correct?

Why do I get error domain is not a suffix of localhost? I guess I don't understand and it is probably something very easy for you guys who have done this before...

bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72

1 Answers1

1

Change

header("Access-Control-Allow-Origin: *");

to

header("Access-Control-Allow-Origin: www.yoursite.com");
Charlie
  • 22,886
  • 11
  • 59
  • 90
  • Ok, thanks! If I have three domains, can I just do like header("Access-Control-Allow-Origin: www.yoursite.com, www.yoursecondsite.com, www.yourthirdsite.com"); ? One of my issue is: Why does not document.domain = "{example.com}"; work? Can you give an example how to achieve what I want? Basically just to fetch some content from server and client. – bestprogrammerintheworld Jan 12 '16 at 16:12