I'm trying to figure out how to load a seperate php page into a div when I click on a div button.
Ie: #div1 opens up #display with one.php within, #div2 opens up #display with two.php, etc..
Any suggestions?
Use ajax for this: http://api.jquery.com/jQuery.ajax/ , or load: http://api.jquery.com/load/
Use jquery's load method to load content on click event.
You could use AJAX For this:
$('#div1').on("click",function(){
var url= "page1.php"; //insert your URL
$.ajax({
url: url,
success: function(data){
$('#div1').html(data); //copy and paste for your special case
}
});
});
Documentation:
There are several ways. By "load PHP page in div", I will suppose you mean "load the output of a PHP page in div".
The simplest way, if you really just want to load some HTML response (without the need of generating a POST request), is to use jQuery's load function.
$(document).ready(function () {
$('#div1').click(function() {
$('#display').load('one.php');
});
$('#div2').click(function() {
$('#display').load('two.php');
})
$('#div3').click(function() {
$('#display').load('three.php');
})
});
try like below
$('#div1').click(function(){
$('#display').load('one.php', function() {
alert('Load was performed.');
});
});
$('#div2').click(function(){
$('#display').load('two.php', function() {
alert('Load was performed.');
});
});
Use Ajax for that:
$.post("GetData.jsp",
{ name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
}
);