On my server, php is not supported. So I have been trying to implement a util that uses the servers date and time to validate forms and such. I am using javascript but am having trouble with the server-side part.
I have tried in the following code, but it works only in Opera, Mozilla, Safari
In IE, i get nothing for 'st' and 'NaN' obviously for date
Code:
var xmlHttp;
function srvTime(){
try {
//Firefox, opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (err1) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (err2) {
try {
xmlHttp = new ActiveXObject('Microsoft.XMLHTP');
}
catch (err3) {
//AJAX not supported, use CPU time.
alert("AJAX not supported");
}
}
}
xmlHttp.open('GET',window.location.href.toString(),false);
xmlHttp.setRequestHeader("Content-Type", "text/html");
xmlHttp.send('');
return xmlHttp.getResponseHeader("date");
}
var st = srvTime();
var date = new Date(st);
.html file
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript" src="date.js">
</script>
</head>
<body>
<script>document.write(st);</script>
<p>converted date: </p>
<script>document.write(date);</script>
<p>cpudate: </p>
<script>document.write(Date());</script>
</body>
</html>
If i am unable to do it this way, is there a way to use perl with javascript.