PHP if statement if page was loaded using ajax

I have a page that loads with a div populated from the include file (pullList.php), but if you click the button (let them say β€œreload”), the contents of the div will reload using the same file (pullList.php).

The problem is that when the page loads through ajax (with jquery), I need the include file (function.php) inside the pullList.php file that is already included in the page.

So, ideally, I would like to write an expression that says

if(the page was loaded with ajax) { include(function.php); } 

Thus, the function.php file will be loaded only once, and if the page is requested again via ajax, it has the right functions to display the content correctly.

I tried using include_once but did not work - had the same problem. Any suggestions?

Thanks!

+7
source share
3 answers
 if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { include(function.php); } 
+10
source
 function isAjax() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')); } 

Source: http://snipplr.com/view/1060/check-for-ajax-request/

+6
source

Check out $ _SERVER ["HTTP_X_REQUESTED_WITH"] containing xmlhttprequest

+2
source

All Articles