How to remove checkout fields from specific products in checkout page

add_filter( 'woocommerce_checkout_fields' , 'hide_checkout_fields' );

function hide_checkout_fields( $fields ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$id = $product->get_id();
$products = array(2516, 584, 2454); // Product Ids

if (in_array($id, $products)) 
{ 
unset($fields['order']['how_heard']);
unset($fields['order']['member_level']);
}

}
return $fields; 
}

how to run ajax with XMLHttpRequest and php

Here is the main file code index.php

<html>
        <head>
            <script>
                function recivemessage(str){     
                    var msz;        
                    if(window.XMLHttpRequest){
                        msz = new XMLHttpRequest();
                    }
                    else{
                        alert("failed");
                    }
            msz.open("GET","response.php?msg="+str,true);
            msz.send();
                }
            </script>
        </head>
        <body>
        <input type="button" value='ok' onclick="recivemessage('ssss')" >
        </body>
    </html>


--------------------------------
Here is the response code

<html>
    <body>
        <h1>Server1</h1>
    <?php
    $msg=$_GET['msg'];
    echo  $msg;
    ?>
    </body>
    </html>