how to detect the Http Request that it is a simple post ot ajax post
<?php
$isXmlHttpRequest = array_key_exists('X_REQUESTED_WITH', $_SERVER) &&
$_SERVER['X_REQUESTED_WITH'] == 'XMLHttpRequest';
if ($isXmlHttpRequest) {
}
else {
}
?>
and if you want to return json data to the ajax request thencode will be
Outputting JSON data for Ajax requests only
<?php
$isXmlHttpRequest = array_key_exists('X_REQUESTED_WITH', $_SERVER) &&
$_SERVER['X_REQUESTED_WITH'] == 'XMLHttpRequest';
if ($isXmlHttpRequest) {
$data = array(
'foo' => 'bar'
);
header('Content-type: application/json');
echo json_encode($data);
exit;
}
?>
|