I just started making a PHP/AJAX site and I was wondering where I should add the functionality to ‘only include the content’.
Should I have if statements in my header and footer scripts that check for a ‘ContentOnly’ get parameter? And then append that parameter to the query strings in my AJAX calls?
Or should I use a filter on the AJAX side to only grab the main content Div. Like in jquery:
$(this).load('/myPhpPage.php #mainContentDiv')
The first method would be faster right? But the second method would keep the AJAX functionality on the presentation side, and out og my PHP.
Or is there a third method? I want to keep my PHP scripts intact, so that if oyu go to them directly, the header and footer are there. Thanks in advance!
Please don’t use AJAX for the sake of using AJAX.
That said, most AJAX libraries pass a
X-Requested-WithHTTP header indicating that it’s an AJAX request. You can use that header to decide whether to include your header/footer etc.