我有一个主PHP文件,其中包含我的主页的内容,例如index.php.
在该页中,我调用一个JavaScript文件,该文件为我的按钮div运行一个my_subview ID的函数。
在这个函数中,我有一个叫做content的东西,它基于某人为我做的一个类,当我把'This is content'放进去时,它会以模态显示那个句子。
如何让内容显示另一个PHP文件的内容,称为subview_php?
你的内容div将是:
<div id="content"></div>
<input type="button" id="my_subview">
<input type="button" id="subview">
<div id="wait"></div>
必须使用jQuery+Ajax,代码如下:
$("#my_subview").click(function(){
$.ajax({
type:"post",
url:"my_subview.php",
beforeSend: function(){
$('#wait').html('<img src="img/Loading.gif"/> Loading Data');
},
success:function(data){
$("#content").html(data); //Show in the div "content" a my_subview.php data
$('#wait').html('');
}
});
});
$("#subview").click(function(){
$.ajax({
type:"post",
url:"subview.php",
beforeSend: function(){
$('#wait').html('<img src="img/Loading.gif"/> Loading Data');
},
success:function(data){
$("#content").html(data); //Show in the div "content" a subview.php data
$('#wait').html('');
}
});
});
当你点击div "content"中的第一个按钮时你会显示my_subview。php data当你点击第二个按钮时你会在同一个div "content"中显示subview。php data