Sem Sorock
Sem Sorock

Reputation: 11

jquery load remote html page

I whant to load remote html page and then parse it. There are bunch of such examples but could anybody explain why I receive this error:

XMLHttpRequest cannot load http://html.comsci.us/examples/blank.html. Origin null is not allowed by Access-Control-Allow-Origin.

when I try to load this html page:

<!DOCTYPE HTML>
<html>
  <head>
  <script type="text/javascript"
     src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script>
      $(document).ready(function(){ 
        $.get('http://html.comsci.us/examples/blank.html', function(data) {
           alert('Load was performed.');
        }); 
      });
    </script>
  </head>
  <body>
  </body>
</html>

Upvotes: 1

Views: 6608

Answers (2)

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

The security restriction you are hitting is called "same origin policy" or "cross-domain access".

Ways to work around:

  • make query server side or with client application
  • if both sites agree on access you can use CORS, running code on other site
  • JSONP if other site supports it

Upvotes: 0

gcochard
gcochard

Reputation: 11744

You need to create a script on your own server that requests that page, and you call that script using your ajax request.

Upvotes: 0

Related Questions