如何在插入之前在ajax / javascript / php中延迟几秒钟

<?php
    include_once("connect.php");
    if(isset($_POST))
    {
        $sno=$_POST['sno'];
        $start_date=$_POST['start_date'];
        $end_date=$_POST['end_date'];
        $amount=$_POST['amount'];
        $lease_id=$_POST['lease_id'];
        if($lease_id == 0){
            $lease_id=1;
        }
        $calendar_type=$_POST['calendar_type'];
        $rph=$_POST['start_date']." - ".$_POST['end_date'];
        $sql="INSERT INTO tbl_lease_details(lease_id,sno,start_date,end_date,amount,calendar_type,rph,stat) VALUES ('$lease_id','$sno','$start_date','$end_date','$amount','$calendar_type','$rph','not_paid')";

        $result=mysql_query($sql);
        if($result){

            echo "successfully inserted";
        }
    }
    mysql_close($rs);
    mysql_close($connect);
?>

I need to add a "loader" in order to make some delay before inserting into database. I tried my best but I couldn't, please help me to solve this issue.

In php we can add dealy using sleep function. please check below code

     echo date('h:i:s') . "<br>";

    //sleep for 5 seconds
    sleep(5);

    //start again
    echo date('h:i:s');