Reputation: 14511
I am looking for some code that will load a page inside of a DIV w/ JQuery.
Basically, when the page loads I would like to load
displaycatch.php into a DIV
<div id="results">Content for id "results" Goes Here</div>
Then, I would like to create a button that loads a different page inside that DIV content.
Any help is appreciated.
Thanks!
Upvotes: 0
Views: 773
Reputation: 12146
$(document).ready(function(){
$('#results')
.load('displaycatch.php')
.after($('<button/>',{text:'Load another','type':'button'}).click(function(){
$('#results').load('displayanother.php')
}));
);
That will load displaycatch.php into #results when page is loaded, then insert button after it, which on click will load different page. Also, it was unclear, if you already have button or want to create it dynamically.
Upvotes: 2
Reputation: 2227
Here is the very simple ajax call from a button. On success, the response is put into your DIV
$("#button").click(function() { $.ajax({ type: "POST", url: "some.php", data: "foo=bar&fooo=baz", success: function(msg){ $("#results").html(msg); } }); });
Upvotes: 2