0

I am new to working with AJAX, what I'd like to be able to do is get the contents of a div from an external site and return it on my own site.

Here is the code I currently have:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script type="text/javascript" src="get-page-content.js"></script>

</head>
<body>
    <h1>Page content should go here:</h1>
    <div id="here"></div>
</body>

</html>

And for my .js script:

$.ajax({
   url: 'http://www.spotlight.com/6298-9058-7917',
   type: 'GET',
   success: function(res) {
      var data = $.parseHTML(res); 
      $(data).find('.skills').each(function(){
          $('#here').append($(this).html());
     });

   }
 });

As expected, this works if it's an external site on the same server, however, when trying to get info from another domain I get the following error: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there anything I can do to work around this error?

Sam Skirrow
  • 3,647
  • 15
  • 54
  • 101
  • Possible duplicate of [AJAX cross domain call](http://stackoverflow.com/questions/2558977/ajax-cross-domain-call) – Patrick Evans May 17 '16 at 18:40
  • Refer [http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Garvit Mangal May 17 '16 at 18:40

1 Answers1

0

For security reasons, you can only include an external page that's on the same domain as the page including it. In fact, the two domains must match exactly, down to the "www" (or lack thereof) part.

but may be you can try http://www.ajax-cross-domain.com/

Arjun Bala
  • 287
  • 1
  • 8