is there difference whether when a page ca开发者_Python百科lled with ajax when called normally? I mean how i could figure out a page called with ajax or called directly ?
You can add a parameter to the call, for example:
xmlhttp.open("GET","page.php?request=ajax",false);
And then check for it in php:
if($_GET['request'] == 'ajax'){
//this was called by ajax!
}
To distinguish between a normal page load, and an AJAX load ... some might code into the JS a variable to pass to the PHP page that indicates AJAX. This would let you modify output as JSON or whatever you wish to do.
Others use separate php scripts for AJAX.
But yeah, there are many ways to figure this out. More details if you have questions, but these are probably the easiest.
Edit: If you did not see the URL posted as the main comment as possible duplicate. this should answer your question about identifying ajax requests only.
Most well-known Ajax frameworks like jQuery and mooTools add a specific header which you can check with PHP:
if (strcasecmp('XMLHttpRequest', $_SERVER['HTTP_X_REQUESTED_WITH']) === 0)
{
// Ajax Request
}
精彩评论