2

I'd like to load a site from a different domain. I've already set headers through php in my header.php file:

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: *");

I've searched around for the correct way to do the ajax request with cross domain enabled and ended up with this:

$.ajax(
{
    type: 'GET',
    url: target,
    processData: true,
    data: {},
    dataType: "json",
    success: function (data)
    {
        $("#toolsarea").attr('src', target);
    }
});

but I still get the error "No 'Access-Control-Allow-Origin". Is there still something I'm missing?

Jaynein
  • 21
  • 3
  • 1
    Possible duplicate of [Access-Control-Allow-Origin error sending a jQuery Post to Google API's](http://stackoverflow.com/questions/6114436/access-control-allow-origin-error-sending-a-jquery-post-to-google-apis) – Sean Dec 18 '15 at 02:33

1 Answers1

0

Your issue is related to Same origin policy which prevent JavaScript to make an AJAX request for security reasons.

You need to make sure CORS is enabled on your PHP server.

You can do it using:

<?php
 header("Access-Control-Allow-Origin: *")

More information on how to enable CORS on your server can be found here:

http://enable-cors.org/server_php.html

You can read more about Same-origin policy on the client here:

https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

GibboK
  • 71,848
  • 143
  • 435
  • 658