Javascript not working for ajax modal function

I am just new to AJAX, JQUERY and following some tutorial on youtube but I’m stuck on some things. So I just changed some things here and adjusted it based on my understanding.

This button will get the project ID that the user wants to approve on the table:

<button type="submit" name="approve" id="<?php echo $displayapprovaldetails['projectid'];?>" class="btn btn-primary btn-sm approve_data">Approve</button>

Now, I have this modal form that will ask for remarks first before approving and updating the records connected to the projectid:

<div class="modal fade" id="approve_data_Modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title font-weight-bold text-primary" id="exampleModalLabel">Approve</h5>
          <button class="close" type="button" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <form method="post">
        <div class="modal-body">
            <label>Remarks: </label>
            <textarea name="remarks" id="remarks" rows="5" class="form-control"></textarea>
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
          <button class="btn btn-primary" type="submit" name="approve" id="approve">Confirm</button>
          </form>
        </div>
      </div>
    </div>

I changed the script to get the variables for both on nested functions but it is still not working. I’m not sure if my script is also correct.

<script>
$(document).ready(function(){

  $(document).on('click', '.approve_data', function(){
     var projectid = $(this).attr("projectid");

     $('#approve_data_Modal').modal('show');
     $(document).on('click', '#approve', function(){
      var remarks = $("#remarks").val();
      var projectid = $projectid;

      if(remarks=="")
      {
        $("#lblRemarks").html("What do you want to say?");
      }

     $.ajax({
        url:"include/approve.php",
        type:"post",
        data:{projectid:projectid, remarks:remarks},
        success:function(data){
          $("#approve_data_Modal").modal('hide');
          }
        });
     });
  });
});
</script>

Can someone help me pinpoint what was wrong with my script and how I could correct it to get the two variables ($projectid and $remarks)?

Thanks.