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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.