Klaus Hartl wrote:
> Depends on what you're using in the backend. if you're using Rails you
> can easily return whats needed depending on the kind of request:
>
> if request.xml_http_request?
> render :layout => false
>
> The same is of course possible with any other backend language. One or
> the other framework for PHP has that already build-in, otherwise you can
> still do the following:
>
> if ($_REQUEST['X-REQUESTED-WITH'] == 'XmlHttpRequest') {
> // It's an Aja request
> }
>
> (can't remember if thats the correct syntax for php)
>
Here is my "slim" PHP ajax detection function;
// returns true if the page has been requested via a browser
XMLHTTPRequest (AJAX call)
function isAjax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER
['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}
My framework detects if a page has been requested via a XMLHTTPRequest,
and if so, disables debugging (extra output), as well as prevents the
template engine from including the header (<html><head><body>..) and
footer. Further, I flag if the page is expected to output JSON, and if
so disable error_display and enable error logging -- so that any PHP
notices/warnings will not botch the JSON return.
~ Brice
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/