Hi I'm trying to send an id using AJAX POST from my front-end to my AJAX php backend. However, I kept getting this error message "Undefined array key "data" " at my backend file...Im not too sure what I did wrong as I had tried many solutions from previous discussions with similar issue but still couldn't get it to work.
My code: front-end
<script>
     $(document).ready(function() {
                $(document).on('click', ".btn-edit", function() {
                  var payroll_history_id = $(this).data('id');
                  var _data = {
                    'id': payroll_history_id,
                  };
                  console.log("data for ajax call", _data);
                  console.log(payroll_history_id);
                  $.ajax({
                    url: "payroll-summary-data.php",
                    method: "POST",
                    dataType: "html",
                    data: {
                      _data
                    },
                    success: function(data) {
                      alert("Hello World");
                      alert(payroll_history_id);
                      alert(data);
                      // $("#payroll_history_id").val(data.payroll_history_id);
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                      alert(xhr.status);
                      alert(thrownError);
                    }
                  })
                })
              })
<script>
Backend:
<?php
$payroll_history_id = $_GET['data'];
json_decode($payroll_history_id);
$userobject = new User();
$payroll_historyobject = new payroll_history();
// $payroll_history_id = escape(Input::get('payroll_history_id'));
$payrollresult = $payroll_historyobject->searchOnly2($payroll_history_id);
$payroll_history_user_id = array();
echo $payroll_history_id;
print_r($payrollresult);
$payroll_historyresultOnly = $payroll_historyobject->searchOnlypayroll_history($payroll_history_id);
for ($i = 0; $i < count($payrollresult); $i++) {
    array_push($payroll_history_user_id, $payrollresult[$i]->user_id);
}
?>
 
    