Update: since WordPress 4.7.0 you can call a function wp_doing_ajax(). This is preferable because plugins that “do Ajax” differently can filter to turn a “false” into a “true”.
Original answer:
If you’re using Ajax as recommended in the codex, then you can test for the DOING_AJAX
constant:
if (defined('DOING_AJAX') && DOING_AJAX) { /* it's an Ajax call */ }