最初のページから受け取ったIDに基づいてデータベースからデータを選択してコンテンツを作成するphpページのjquery-ajax呼び出しを作成しました
最初のページindex.phpには、person1をクリックするとリンクperson1があり、jqueryを介して詳細ページにリダイレクトされます。コードは次のとおりです。
$('.details').click(function() {
$("a").removeClass("active");
$(this).addClass("active");
var id = $(this).attr("id");
$.ajax({
type: "GET",
url: "details.php",
data:{pid:id},
success: function(html){
$("#persons").html(html).fadeIn(1000);
}
});
return false;
});
コンテンツは index.php ファイルにロードされます:
<div class="row">
<div class="twelve columns" id="persons" style="display:none" >
</div>
</div>
詳細ページの内容:
<?
if(isset($_GET['pid'])){
$id=(int)$_GET['pid'];
$sql="select id, name,title,details,image,cat from persons where id ='".$id."' order by name asc";
$rs=mysql_query($sql)or die(mysql_error());
if(list($id,$name,$title,$details,$image,$cat)=mysql_fetch_array($rs)){
?>
<h3><? echo $name;?></h3>
<h5><? echo $title;?></h5>
<p align="justify">
<img alt="<? echo $name;?>" src="images/persons/<? echo $image?>" title="<? echo $name;?>" style="float:right; margin-left:15px;" />
<? echo $details;?>
</p>
<?
}
}
?>
ページが ajax 呼び出しまたは通常の php 呼び出しを介して要求されたかどうかを確認する方法は? ajax呼び出しでない場合は、詳細ページのコンテンツを通常どおりロードしますか?