2013-09-29 95 views
0

我已經通過這種方式(根據「jerjer」所選答案)嘗試,但未能加載內容..如何使用PHP捲曲加載其他網站的內容到一個div在我的網站

Load external site's content

render.php

<?php 
    $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp'; 
    $htm = file_get_contents($url); 
    echo $htm; 
?> 

common.js

$(document).ready(function(){ 
    $('#divId').load('render.php'); 
}); 

index.html

<html> 
<head> 
    <title>Home</title> 
    <link rel="stylesheet" href="css/style.css" type="text/css"> 
    <script src="js/jquery.js"></script> 
    <script src="js/common.js"></script> 
</head> 
<body> 
    <div id="divId"></div> 
</body> 
</html> 

任何幫助嗎?在此先感謝...

+2

iframe。 iframe中。 dun dun dun – MightyPork

+0

此代碼無錯誤。 PHP腳本正確返回外部網站的內容? (沒有錯誤?良好的路徑?)嘗試直接打開render.php到你的瀏覽器。 –

+0

爲什麼要使用AJAX加載render.php?爲什麼不在你的索引中使用php? (so index.php),並在其中包含render.php。 –

回答

1

使用此代碼。確保你已經安裝了捲曲延伸。

$url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp'; 
$htm = getCurlData($url); 
echo $htm; 

function getCurlData($url) 
{ 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    $contents = curl_exec($ch); 
    curl_close($ch); 
    return $contents; 
} 
相關問題