希望在完整的HTML页面加载后执行一些PHP API和脚本,并显示响应。
<html>
<body>
content
<?php
//some php script execute after full page load
?>
</body>
</html>
希望在完整的HTML页面加载后执行一些PHP API和脚本,并显示响应。
<html>
<body>
content
<?php
//some php script execute after full page load
?>
</body>
</html>
PHP是一种服务器端编程语言。它在您请求页面时执行。因此,页面加载后无法执行它。
如果您需要检查客户端是否已加载某些内容,则必须使用客户端编程语言,如JavaScript。
这样,您可以向PHP文件发出请求(将被执行),并处理该文件返回的所有内容。
您可以使用JavaScript或jQuery(一个JavaScript库)来完成此操作:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// Check if the page has loaded completely
$(document).ready( function() {
$('#some_id').load('php-file.php');
});
</script>
$(window).load(function(){ /*This allows to execute your code after the page is rendered fully */
$.get("<path to php file>", function(data){
/* you can then process the ajax response as needed */
});
})