2016-11-26 71 views
0
<!DOCTYPE html> 
<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
    <script> 
     <script type="text/javascript"> 
     jQuery(document).ready(function(){ 
      jQuery("#div1").load("https://www.ae.com/men-s-clearance/web/s-cat/6470582?icid=Clearance:CHP:sec1:Clearance:MensClearance:ShopMen .product-list"); 
     }); 
     </script> 
    </script> 
    </head> 
    <body> 

    <div id="div1"></div> 

    <button>Get External Content</button> 

    </body> 
</html> 

上面的代碼在運行中,但是當我按一下按鈕沒有任何反應。加載一個div類其他網站

+2

如果您想更詳細地編輯您的帖子,例如清楚說明預期的點擊行爲和/或您遇到的錯誤,那將非常棒。 – nyedidikeke

回答

0

首先,你錯了雙<script>包裝:

<script> 
     <script type="text/javascript"> 
     ... 

而且你沒有點擊按鈕的處理程序。所以你點擊後不能得到任何反應。 你也有一個奇怪的部分「.product-list」在URL。你想要什麼? 也許你正在尋找像這樣的水手?

<!DOCTYPE html> 
<html> 
<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
    <script type="text/javascript"> 
     jQuery(document).ready(function() { 
      $('#fetch-btn').click(function() { 
       jQuery("#div1").load("any-url"); 
      }); 
     }); 
    </script> 
</head> 
<body> 

<div id="div1" class="product-list"></div> 

<button id="fetch-btn">Get External Content</button> 

</body> 
</html> 

但它仍然無法加載整個國外網站內容到你的div。你應該爲它使用iframe。你應該閱讀約CORS並嘗試使用任何代理與你的域名。 它有幫助嗎?

0

嘗試使用iframe,如果你想與內部網站

0

你不能從其他網站下載的數據進行交互。 使用用PHP編寫的簡單代理!

echo (file_get_contents($_POST['url'])); 

並使用jQuery!

$.ajax({ 
    url: "./your_proxy.php", 
    type: "POST", 
    data: { 
    url: 'https://www.youtube.com' 
    }, 
    dataType: "html", 
    success: function(data) { 
    var d = $(data); // your data 
    } 
});