In PHP, what are the advantages and disadvantages of using Ajax requests to check if a user input already exists in a list before submission?

When submitting a form with user input, it's often necessary to check if the input already exists in a list before proceeding. Using Ajax requests can help achieve this without refreshing the entire page, providing a smoother user experience. However, it can also introduce additional complexity and potential security vulnerabilities if not implemented correctly.

<?php
// Check if user input already exists in a list
if(isset($_POST['user_input'])) {
    $user_input = $_POST['user_input'];
    
    // Perform necessary validation and sanitization
    
    // Check if input already exists in the list
    $existing_list = ['item1', 'item2', 'item3']; // Example list
    if(in_array($user_input, $existing_list)) {
        echo json_encode(['exists' => true]);
    } else {
        echo json_encode(['exists' => false]);
    }
}
?>