Ben*_*ton 3 javascript php ajax jquery include
I have a php include which takes awhile to load because PHP has to fetch a lot of data. I don't want to slow the whole webpage loading waiting for this include so how can I load this one include with ajax? I don't want the ajax to be triggered by a button click I just want it to load up the include as the page is loading so that if you look at my example below 'Some more html content' would be displayed whilst the inlude.php is still loading in.
<html>
<head>
</head>
<body>
Some html content
<script>
Ajax load 'include.php';
</script>
Some more html content
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是jQuery,则可以使用他们的ajax调用之一从include.php加载html。例如,您可以使用load()函数。
例如:
<div id="content"></div>
<script>
$(document).ready(function() {
$("#content").load("/yourpath/include.php");
});
</script>
Run Code Online (Sandbox Code Playgroud)