0

I want to display a new page in the div but access-control-allow-origin issues.

for example, I try to display www.naver.com

========================================================================

  <link rel="stylesheet"   href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  <script src="js/jquery.ajax-cross-origin.min.js"></script>
  <script>
      $(document).ready(function() {
        var url = 'http://www.naver.com';
    jQuery.ajax({
            type:"GET",
            url : url,
            dataType:"jsonp",
            crossOrigin: true,          
            success : function(data) {
                console.log('success');
                console.log('success:'+url);
                },
            error : function(data) {
                console.log('error');
                }
         });
     $('#openPage').load(url);

    });
 </script>
 <style>
    #btn{
        width: 100%;
        height:50px;
    }

</style>
</head>
<body>
<!-- <div id="btn">
    <button>button</button>
</div> -->
<div id='openPage'></div>

</html>
mygomiii
  • 1
  • 3

2 Answers2

0

You can only make cross-origin AJAX requests if the site that you're making the request to gives your site permission to do it. Naver.com doesn't, so you can't. There's no way around that. If you just want to show a page and don't care about JavaScript access to it, an iframe is the closest thing.

0

The response http header must include "Access-Control-Allow-Origin", and this should be done by Naver.com. Since you can't change it, you can build a proxy server to load the content of Naver.com and send to your page.

MaxPai
  • 1
  • 1