0

Here is the script to load remote content and display in a div

<body>
<script type="text/javascript">
function loadContent(elementSelector, sourceUrl) {
$(""+elementSelector+"").load("http://remote.com/abc.html");
}
</script>
</head>
<body>
<a href="javascript:loadContent('#content', '');">Link 1</a>
<div id="content">content will be loaded here</div>
asfasdfasf
</body>

But it seems there is something security blocking the script about the cross domain ajax, i use xampp as my localhost web server

Error message at chrome console

Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

i've searched some solution such as add

<?php header('Access-Control-Allow-Origin: *'); ?>

but not work.

Any fastest way to solve this problem? thanks

1 Answer 1

1

it is because of same origin policy, it does not allow a page to make a Ajax request to a resource hosted in a different domain.

Since it looks like you are dealing with an HTML content, the only solution is to use CORS if the hosting server supports it

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.