To see if the current request is an AJAX request sent from a js library ( like jQuery ), you could try something like this:
if( ! empty( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] ) &&
strtolower( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ]) == 'xmlhttprequest' ) {
//This is an ajax request.
}