0

I need to access new web page(different domain) from my current page. for that I have used following method.

<?php header("Access-Control-Allow-Origin:*"); ?>  
<script type="text/javascript">
$( document ).ready(function() {
$("#content").load("<?php echo $_GET['url']; ?>");
});
</script>

but it gives me XMLHttpRequest cannot load http://adamsshs.pbworks.com/w/page/44430294/Algebra. Origin http://localhost is not allowed by Access-Control-Allow-Origin. I have search. most of the them are said to use <?php header("Access-Control-Allow-Origin:*"); ?> . I have used that one but still same error. what am I missed.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lahiruzz
  • 665
  • 1
  • 12
  • 24
  • 3
    The access control header needs to be on the server-end of the communication, ie the other website. If they don't set it and don't provide a JSONP API, you'll have to resort to other, non-client-side means – Phil Oct 01 '13 at 06:09
  • you mean i need put in http://adamsshs.pbworks.com/w/page/44430294/Algebra. is that? – Lahiruzz Oct 01 '13 at 06:12
  • Yup, good luck with that ;). Alternatively, you could create a local PHP proxy file to fetch the page contents and return them to your JavaScript – Phil Oct 01 '13 at 06:14

1 Answers1

0

Is because the cross domain policy.

If you want to called ajax cross domain you have to use JSONP for called cross domain

jquery with JSONP - http://api.jquery.com/jQuery.getJSON/#jsonp

This is related to your question - Simple jQuery, PHP and JSONP example?

Community
  • 1
  • 1
Chokchai
  • 1,684
  • 12
  • 12