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)