Php 如何使用jQuery/javascript检索内容已更改的远程网页?
我这里有两个文件,分别位于不同的主机上 test1.phpPhp 如何使用jQuery/javascript检索内容已更改的远程网页?,php,jquery,Php,Jquery,我这里有两个文件,分别位于不同的主机上 test1.php <?php $curl = curl_init("http://myhost.com/test2.php?tempvar=testonly"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($curl); curl_close($curl); echo $output; ?> test2.php <script src=
<?php
$curl = curl_init("http://myhost.com/test2.php?tempvar=testonly");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
echo $output;
?>
test2.php
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log(getURLParameter("tempvar"));
//$("#test").html(getURLParameter("tempvar"));
function getURLParameter(name) {
return (decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search.toLowerCase())||[,""])[1].replace(/\+/g, '%20'))).toUpperCase();
}
});
</script>
<div id="test"><?php echo $_GET['tempvar']; ?> - test</div>
从test2.php中可以看出,我使用php echo函数显示URL变量的内容。这很好用
我的问题是,当我在test2.php中使用jQuery来更改页面内容时,curl函数没有得到更新的页面内容
有没有办法解决这个问题?或者是一个解决办法
我正在使用的页面/代码只是某种实验。因此,使用echo函数不是问题。真正涉及的网页/代码包括通过jQuery操作页面内容的代码
我来这里之前搜索过网,什么也没找到。我试图使用http_get PHP函数,但遇到了服务器问题,我已向我们的服务器团队报告了这些问题
非常感谢。您不能使用PHP获取页面加载后加载的JS填充结果。试试PhantomJS/CasperJS。这个评论是对这个问题的一个非常好和精确的回答。