これがあなたの見解だと想像してください
<html>
<head>
$(document).ready(function() {
$("#add").on("click", function(e) {
var user_id = $('#user_id').val();
var time = date();
var department = $('#department').val();
var data = {uid:user_id, time:time, dept:department};
$.ajax({
url: "add_into_db.php",
type: 'POST',
data: data,
success: function(msg) {
if(msg=="true"){
alert("Your dats is inserted successfully");
document.location.reload(true);
}
else{
alert("Your data insertion failed");
return false;
}
}
});
e.preventDefault();
});
});
</head>
<body>
// Some html here
// input field for user
// input field for time
// input field for department
// whatever data you want os send on click, include it here
<input id ='add' type= 'submit' value 'Add'/> //Your submit button to add data via AJAX
</body>
データベースにデータを追加する Yout php 関数
function add_into_db(){
$user id = $_POST['user_id'];
$time = $_POST['time'];
$dept = $_POST['department'];
// connect to your db
// run your insert query
If (insertion is successfull) {
$msg = 'true';
echo $msg;
}
else{
$msg = 'false';
echo $msg
}
}
それがあなたを助けてくれることを願っています