2021-03-30

automatically updates the table without refreshing/reloading the page

I would like to ask if how do I get the latest update of my data that is displayed in my table without reloading or refreshing it. The insertion of the data is already good, it already inserts however I see that the page is still reloading. I am still new to ajax and sweetalert using the client-side.

addingUser.php

$(document).ready(function(){
    $('#addStudent').click(function(e){
        e.preventDefault();
        Swal.fire({
            title: "Are you sure?",
            text: "New student will be added added!",
            icon: "success",
            showCancelButton: true,
            allowEscapeKey : false,
            allowOutsideClick: false
        }).then((result) => {
            if (result.isConfirmed) {
                var valid = this.form.checkValidity();
                if(valid){
                    var studentNumberId = $('#studentNumberId').val();
                    var studentFullName = $('#studentFullName').val();
                    var studentPassword = $('#studentPassword').val();
                    var studentEmail = $('#studentEmail').val();
                    var studentYearBlock = $('#studentYearBlock').val();
                        e.preventDefault()
                        $.ajax({
                            type: 'POST',
                            url: 'includes/model_addStudent.php',
                            data: {studentNumberId: studentNumberId,studentFullName: studentFullName,studentPassword: studentPassword,studentEmail: studentEmail,
                                studentYearBlock: studentYearBlock},
                            success: function(data){
                                Swal.fire({
                                    title: "Successfully Added!",
                                    text: "New student has been added!",
                                    icon: "success"
                                }).then(function() {
                                    // update page without refreshing/reloading....
                                    location.href = "ManageStudent.php";
                                });
                            },
                            error: function(xhr, thrownError, ajaxOptions){
                                Swal.fire({
                                    title: "Successfully Added!",
                                    text: thrownError,
                                    icon: "info"
                                })
                            } 
                        });
                }
                else {
                    Swal.fire({
                        title: "Error!",
                        text: "Invalid Form",
                        icon: "warning"
                    });
                }
            }
            else {
                Swal.fire(
                'No Changes!',
                'No New Student has been added.',
                'info'
                )
            }
        });   
            });      
    });

Thank you so much.



from Recent Questions - Stack Overflow https://ift.tt/3u4FIb1
https://ift.tt/eA8V8J

No comments:

Post a Comment