autofill php form data from MySQL database not working

I tried to create form to show owner detail by autoloading when enter owner NIC(national id card) details in one row. but I took several method by changing names etc. but nothing works. no errors on console. data field in form not generating.
database structure db structure

I try to change parameter names and array structure but it not give any result in lower input
fieldsoutput view after run
my form details as follows

<?php 
include_once 'connection.php'; 
?>
<?php 
$sql="SELECT owner_nic FROM ownerdetails";
$result= mysqli_query($con, $sql);
?>

<form action="" >
    <table>
        <tr>
            <td>Owner NIC</td>
            <td>
                <select name="ownernic" id="ownernic" onchange="fetchOwnName()">
                    <option value="">Select NIC</option>
                    <?php 
                        while($rows = mysqli_fetch_array($result)){
                            $nic = $rows['owner_nic'];
                            echo '<option value="'.$nic.'">'.$nic.'</option>';
                        }
                     ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>Owner Name</td>
            <td><input type="text" name="ownername"></td>
        </tr>
        <tr>
            <td>Residence</td>
            <td><input type="text" name="ownerresadd"></td>
        </tr>
        <tr>
            <td>Phone</td>
            <td><input type="text" name="ownerphone"></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><input type="text" name="owneremail"></td>
        </tr>
        <tr>
            <td>Gender</td>
            <td><input type="text" name="ownergender"></td>
        </tr>
        

    </table>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
    function fetchOwnName() {
        // body...
        var nic =document.getElementById("ownernic").value;

        // alert (nic);

        $.ajax({
            url:'farmdetail.php',
            type: 'POST',
            data:{
                x : nic
            },
            dataType: "JSON",
            success: function(data){
                document.getElementById("ownername").value = data.ownerName;
                document.getElementById("ownerresadd").value = data.ownerresAdd;
                document.getElementById("ownerphone").value = data.ownerPhone;
                document.getElementById("owneremail").value = data.ownerEmail;
                document.getElementById("ownergender").value = data.ownerGender;

            }

        })
    }
</script>


farmdetail.php file as follows

<?php 
include_once 'connection.php'; 
?>

<?php 
$nic =$_POST["x"];
$sql="SELECT * FROM ownerdetails WHERE owner_nic ={$nic}";
$result= mysqli_query($con, $sql);
while ($rows = mysqli_fetch_array($result)) {
    // code...
    $data['ownerName'] = $rows["ownername"];
    $data['ownerresAdd'] = $rows["resdence_add"];
    $data['ownerPhone'] = $rows["phone_no"];
    $data['ownerEmail'] = $rows["email"];
    $data['ownerGender'] = $rows["gender"];

    }
    echo json_encode($data);
 ?>