I have created jquery-ajax call for php page that creates content by selecting data from database based on the id it receives from the first page
the first page index.php have link person1 when I click on person1 it redirects through jquery to details page here is the code :
$('.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;
});
The content will be loaded here in index.php file:
<div class="row">
<div class="twelve columns" id="persons" style="display:none" >
</div>
</div>
the content of details page :
<?
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>
<?
}
}
?>
how to check if the page has been requested via ajax call or normal php call? and if it is not ajax call, load the content of details page normally ?
You can check the following variable:
It should be ‘xmlhttprequest’ for AJAX requests.
However, you could simply add a parameter to the URL:
And simply check the URL variable.