Reputation:
I have page.php with about 10 JS files:
PAGE.PHP
<script type="text/javascript" src="somefile1.js"></script>
<script type="text/javascript" src="somefile2.js"></script>
<script type="text/javascript" src="somefile3.js"></script>
...
<div id="pictures"></div>
...
in this page I have some pictures, that need all this js, and a AJAX function to do an pagination after each 10 pictures:
AJAX
next page ->
$.post('/LOADMORE.php',{
'group_no': track_load,
'idpag': idpag
},
Ok, when user click in next page the AJAX will call LOADMORE.PHP to load more pictures in div id="pictures"
this pictures need some Jquery (as the pictures above - this jquery functions is in PAGE.PHP already) functions to open pictures bigger in the screen and other things.
What happening is that the scripts in PAGE.PHP does not work with the pictures loaded using AJAX pagination. So I need to include all 10 js files in LOADMORE.PHP too:
<script type="text/javascript" src="somefile1.js"></script>
<script type="text/javascript" src="somefile2.js"></script>
<script type="text/javascript" src="somefile3.js"></script>
<?php
$stmt = $mysqli->prepare("SELECT * FROM posts ORDER BY id DESC LIMIT ?");
...
while($l = $result->fetch_assoc()) {
echo"<img src=$picture>";
}
?>
My question 1 is, is it right, do I need to include JS in loadmore.php for this to work?
Question 2: if it is right, there is no problem that this <script>
in loadmore.php is not on the <head>
tag? because the loadmore.php is just a PHP function that select pictures in mysql and bring it to the user, there is no <head><title><body>...
should I use this tags?
Upvotes: 1
Views: 99
Reputation: 281
I would like to suggest that you should use switch-case for this to work properly. There is no need to include all files in all pages and u don't have to use all that tags in LOADMORE file. Do 1 thing use switch case give page name as case and in that perticular page use all JS files you are desire to. As shown below by using this method you don't have to include unnecessary files in all pages and your code just work fine. For Ex:-
switch($page)
{
case "PAGE":
<script type="text/javascript" src="somefile1.js"></script>
<script type="text/javascript" src="somefile2.js"></script>
<script type="text/javascript" src="somefile3.js"></script>
break;
case "LOADMORE":
<script type="text/javascript" src="somefile4.js"></script>
<script type="text/javascript" src="somefile5.js"></script>
<script type="text/javascript" src="somefile6.js"></script>
break;
default:
<script type="text/javascript" src="commonjs1.js"></script>
<script type="text/javascript" src="commonjs2.js"></script>
<script type="text/javascript" src="commonjs3.js"></script>
break;
}
Upvotes: 1
Reputation: 1190
Are you giving an unique id to the containers or elements of the pictures you load in LOADMORE.PHP ? If you do so and they make sense for your js in PAGE.PHP... should just work
Upvotes: 0