i want to get time of server with ajax,php,javascript
i use under scritp and with method onload i get time on server and show on the page
so i want in a period time the same function is run but
result is fixed and error is given
my script is
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Untitled Document</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <script language = "javascript">
- var XMLHttpRequestObject = false;
- if (window.XMLHttpRequest)
- {
- XMLHttpRequestObject = new XMLHttpRequest();
- }
- else if (window.ActiveXObject)
- {
- XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
- }
- function getData(dataSource, divID)
- {
- if(XMLHttpRequestObject)
- {
- var obj = document.getElementById(divID);
- var rand = Math.floor(Math.random()*59884555445);
- var ds= dataSource+'?rand='+rand;
- XMLHttpRequestObject.open("GET", ds);
- XMLHttpRequestObject.onreadystatechange = function()
- {
- if (XMLHttpRequestObject.readyState == 4 && (XMLHttpRequestObject.status == 200 || XMLHttpRequestObject.status == 0))
- {
- obj.innerHTML = XMLHttpRequestObject.responseText;
- }
- }
- XMLHttpRequestObject.send(null);
- }
- window.setTimeout("getData("+dataSource+","+ divID+")",1000);
- }
- </script>
- </head>
- <body onLoad="getData('time.php','idtarget')">
- <div id="idtarget"></div>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <?php
- echo date("H:i:s");
- ?>
thanks alot