I'm afraid I don't know JQuery, but here it is using Javascript. I've annotated it to make it easier to understand the process.
PHP Code:
<!DOCTYPE html>
<html>
<head>
<!-- Page Title -->
<title>Ajax Code Injection Example</title>
<!-- Meta Block -->
<meta content="text/html; charset=iso-8859-1" http-equiv="content-type" />
<meta content="Ajax Code Injection Example" name="description" />
<meta content="Ajax, Code Injection, Example" name="keywords" />
<meta content="all,index,follow" name="robots" />
<meta content="noodp" name="msnbot" />
<meta content="global" name="distribution" />
<!-- Javascript Scripts -->
<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {
$("button").click(function () {
alert('Load was performed.');
$.get('getHTML.php', function (data) {
// Create a new DIV to house Ajax HTML
var divAjax = document.createElement('div');
divAjax.setAttribute('id', 'divAjax');
divAjax.setAttribute('style', 'display:none');
divAjax.innerHTML = data;
// Inject the DIV to the body of the page
document.appendChild(divAjax);
// Grab newly injected DIV information
divAjax = document.getElementById('divAjax');
// Grab article DIV to output information
var divArticle = divAjax.getElementById('divArticle');
// Inject relevent information from divAjax into divArticle
divArticle.innerHTML = document.getElementById('article-content-main').innerHTML;
// Clean up body of page
document.removeChild(divAjax);
// DEBUG
// alert('Load was performed.');
});
});
});
//]]>
</script>
</head>
<body>
<div id="divArticle">
</div>
<button>
Get CD info</button>
</body>
</html>
Bookmarks