Currently booked up!

Skill Tag: AJAX


Wed 30th Nov
 

PHP Check for an AJAX call

I just learned that it’s possible to check in php if a request has been made through an ajax call which is handy when you want to return a different template depending on if it’s ajax or not. To do it you just add this snippet:

function is_ajax(){
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

Tue 14th Jun
 

WordPress & AJAX

Reading a free book today called WordPress & AJAX. It has an interesting technique for manually loading the WordPress environment on page 78. When I do anything with AJAX in the theme I usually use a conditional in the template page to catch an AJAX request & display just the barebones data needed. I might try this method for admin pages in plugins though.