我在mysqli中编辑数据后如何自动刷新页面。我已经实现了如下所示的重载功能,但它不起作用。
$('#insert').click(function() { location.reload(); });
我想让它像我点击更新数据一样,页面将显示更新的数据,否则我将不得不点击刷新以显示更新的数据。
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/bootstrap.min.js" type="text/javascript"></script>
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" />
<?php
include('../connect.php');
// Attempt query
$sql = "SELECT * FROM `applicant`";
$result = mysqli_query($Conndb, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>". $row["FULL_NAME"]. "</td>" .
"<td>". $row["IC_NO"]. "</td>" .
"<td>". $row["AGE"]. "</td>" .
"<td>". $row["GENDER"]. "</td>" .
"<td>". $row["CONTACT"]. "</td>" .
"<td>
<a href=\"active.php? id=" . $row['APPLICANT_ID'] . "\" onclick=\"return confirm('Are yousure?'); \">Activate</a></td>" ?>
<td><input type="button" name="view" value="view" id="<?php echo $row["APPLICANT_ID"]; ?>" class=btn btn-info btn-xs view_data"></td>
<td><input type="button" name="edit" value="edit" id="<?php echo $row["APPLICANT_ID"]; ?>" class="btn btn-info btn-xs edit_data"></td>
<?php echo "</tr>"; ?>
<script>
$(document).ready(function(){
$('#insert').click(function() {
location.reload();
});
$('#add').click(function(){
$('#insert').val("Insert");
$('#insert_form')[0].reset();
});
$(document).on('click', '.view_data', function(){
var applicant_id = $(this).attr("id");
$.ajax({
url:"selected.php",
method:"POST",
data:{applicant_id:applicant_id},
success:function(data){
$('#applicant_detail').html(data);
$('#dataModal').modal('show');
}
});
});
$(document).on('click', '.edit_data', function(){
var applicant_id = $(this).attr("id");
$.ajax({
url:"fetch.php",
method:"POST",
data:{applicant_id:applicant_id},
dataType:"json",
success:function(data){
$('#name').val(data.FULL_NAME);
$('#ic').val(data.IC_NO);
$('#gender').val(data.GENDER);
$('#age').val(data.AGE);
$('#nationality').val(data.NATIONALITY);
$('#race').val(data.RACE);
$('#other_race').val(data.OTHER_RACE);
$('#address').val(data.ADDRESS);
$('#contact').val(data.CONTACT);
$('#marital_status').val(data.MARITAL_STATUS);
$('#property').val(data.PROPERTY);
$('#monthly_rent').val(data.MONTHLY_RENT);
$('#working_or_not').val(data.WORKINGORNOT);
$('#applicant_id').val(data.APPLICANT_ID);
$('#insert').val("Update");
$('#add_data_Modal').modal('show');
}
});
});
$('#insert').click(function() {
location.reload();
});
$('#insert_form').on("submit", function(event){
event.preventDefault();
if($('#name').val() == "") {
alert("Name is required");
} else {
$.ajax({
url:"insert.php",
method:"POST",
data:$('#insert_form').serialize(),
beforeSend:function(){
$('#insert').val("Inserting");
},
success:function(data){
$('#insert_form')[0].reset();
$('#add_data_Modal').modal('hide');
$('#employee_table').html(data);
}
});
}
});
});
</script>
<?php
}
} else {
echo "0 results";
}
//Close connection
mysqli_close($Conndb);
?>