While requesting a php page from the server using .load() api, or for that matter the .ajax() api of jquery, should the php page be a complete one with all the tags and markings, and also the should it have the database connection details in it?
I tried linking the php page using .load() but it does not seem to work. My php page that is being requested would have lots of images and stuff in it. How do I have this php page displayed using the load() api?
thanks.
I believe that the best practice is to load the resource you want to update dynamically,i.e. only load a partial page.
When loading full pages, it's likely that you're loading a lot of data that you don't need.
Instead, I'd make a block with the html/images/script that you want to update dynamically, and just load this.
<html>
<body>
<h1>About me</h1>
<p>Some data about me</p>
<div class="latest-photos"> </div>
</body>
</html>
<ul>
<li>
<img src="myphoto1.jpg">
</li>
<li>
<img src="myphoto2.jpg">
</li>
</ul>
jQuery(function($){
$(".latest-photos").load("gallery.block.php");
});
If your php page needs a database connection you have to specify everything in it in order to display your images.
Another thing, when using the load method, it's not necessary that your called page should have a complete html structure.
$("#container").load("page.php");