Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
70
rated 0 times [  72] [ 2]  / answers: 1 / hits: 33080  / 11 Years ago, wed, june 5, 2013, 12:00:00

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>

More From » php

 Answers
25

If you're using jQuery, you could you use one of their ajax calls to load your html from include.php. For example you could use the load() function.



For example:



<div id=content></div>

<script>
$(document).ready(function() {
$(#content).load(/yourpath/include.php);
});
</script>

[#77806] Tuesday, June 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;