Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display the server time with the use of ajax

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.59k
    Comment on it

    In this tutorial , you will learn that how to get the server time automatically with the use of jQuery-ajax code. We can make the simple input form in html for time.When the name is input by the user , the time input feild will automatically called from the server. You can use the below code fo getting the time automatically from server in input boxes

    <html>
    <body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
    
    //jquery and ajax function used to get the server time in the box
    $(document).ready(function(){
    $("#name").change(function(){
    $.ajax({
    url: "serverTime.php",
    success: function(result){
    $("#time").val(result);
    }
    });
    });
    });
    //-->
    </script>
    //html for input box showing the server time
    <form name='myForm'>
    Name: <input type='text' name='name' id="name">
    Time: <input type='text' name='time' id="time"/>
    </form>
    </body>
    </html>

    You can save this code in any of the named html file. after saving this code we can make other file to get the time of the server.You can save the file name serverTime.php as its already called above.

    Here is the code for the file.

    <?php echo date("H:i:s");?>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: