How can search engine optimization be affected by using AJAX to load content in PHP websites?

When using AJAX to load content in PHP websites, search engine optimization can be affected because search engine crawlers may have difficulty indexing content that is loaded dynamically. To solve this issue, it is important to ensure that all content is accessible without JavaScript enabled, and to use server-side rendering to generate content that search engines can crawl.

<?php
// Check if the request is an AJAX request
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    // Process AJAX request and return content
} else {
    // Serve content for non-AJAX requests
}
?>