How come my codes won't work? :( It won't upload... (jquery, ajax) FILE UPLOAD : I need help to upload a file using ajax without refreshing the page. (I tried using form element it works... but it redirects to the other page).

    <!DOCTYPE html>
    <html>
    <head>
      <title> Test File Upload </title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
    
      <input type="file" name="file" id="file"><br><br>
      <button id="submitbtn"> Upload </button>
    
    </body>
    <script>
    $(document).ready(function(){
      $("#submitbtn").click(function(){
    
        var property = document.getElementById('file').files[0];
        var formData = new FormData();
    
        formData.append("file", property);
    
        $.ajax({
          url: "AjaxPhp.php",
          type: "POST",
          data: formData,
          cache : false,
          contentType : false,
          processType : false,
          dataType: "json",
          success: function(testresponse){
            if(testresponse.success == true){
              alert(testresponse.messages);
            } else {
              alert(testresponse.messages);
            }
          }
        })
      });
    });
    </script>
    </html>

this is my php file... please help :) thank you so much!

    <?php
    $con = mysqli_connect("localhost", "root", "", "learningdb") or die("connection failed");
    
    if($_POST){
    
    $target_dir = "testupload/";
    $target_file = $target_dir . basename($_FILES["file"]["name"]);
    
    if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){
    
      $sql = "INSERT INTO uploadfile(image) VALUES ('$target_file')";
      mysqli_query($con, $sql);
    
      $valid['success'] = true;
      $valid['messages'] = "Successfully Uploaded!";
    } else {
      $valid['success'] = false;
      $valid['messages'] = "Something went wrong...";
    }
    echo json_encode($valid);
    }
    ?>

Thank you in advance for to whoever could fix my problem. Arigato.