Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用php curl将另一个站点内容加载到我的站点的div中_Javascript_Php_Jquery_Curl - Fatal编程技术网

Javascript 如何使用php curl将另一个站点内容加载到我的站点的div中

Javascript 如何使用php curl将另一个站点内容加载到我的站点的div中,javascript,php,jquery,curl,Javascript,Php,Jquery,Curl,我尝试过这种方式(根据“jerjer”的选择答案),但未能加载内容 <?php $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp'; $htm = file_get_contents($url); echo $htm; ?> $(document).ready(function(){ $('#divId').load('render.php'); }); <htm

我尝试过这种方式(根据“jerjer”的选择答案),但未能加载内容

<?php
    $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp';
    $htm = file_get_contents($url);
    echo $htm;
?>
$(document).ready(function(){
    $('#divId').load('render.php');
});
<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>
render.php

<?php
    $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp';
    $htm = file_get_contents($url);
    echo $htm;
?>
$(document).ready(function(){
    $('#divId').load('render.php');
});
<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>
index.html

<?php
    $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp';
    $htm = file_get_contents($url);
    echo $htm;
?>
$(document).ready(function(){
    $('#divId').load('render.php');
});
<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>

有什么帮助吗?提前感谢…

使用此代码。确保安装了curl扩展

 $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;
}

iframe。iframe。这个代码中没有错误。php脚本是否正确返回外部网站的内容?(没有错误?路径正确?)尝试直接在浏览器中打开render.php。为什么要使用AJAX加载render.php?为什么不在索引中使用php?(所以index.php)并在那里包括render.php。我必须根据需要修改呈现的内容。。。这意味着我需要扣除一些内容。确保您的服务器允许在PHP中使用cURL