jQuery load external page

06.Jul.2010

You can use jQuery function load() to load external page. Therefore, you can easily make dynamically loaded content on your website.

Let’s say you want to load page “content.php” into div on your page. A whole page would contain next snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<div id="content-container">
	<!-- replace this content with external page -->
</div>
 
<a href="javascript:void(0);" onclick="loadExternalContent();"
title="jQuery Load external page">
	jQuery load external page
</a>
 
<script>
function loadExternalContent() {
	jQuery('#content-container').load('/content.php', function() {
		alert('External page loaded!');
	});
}
</script>