2013-09-29 37 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; 
} 
相关问题