客户端改变用户名字以后,在时间:后面显示输入名字的时间。
问题:time.asp(在最后)如果用php实现该用代码?请指教
运行您的AJAX应用程序
请在下面的文本框中键入一些文本,然后单击时间文本框:用户: 时间:
时间文本框可在不加载页面的情况下从"time.asp"获得服务器的时间!
//index.php
<html>
<head>
</head>
<body>
<script type="text/javascript">function ajaxFunction()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch(err)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
}
//Send
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.Open("GET","time.php",true);
xmlHttp.Send(null);
}</script>
<form name="My Form">
用户:<input type="text" name="userName" onkeyup="ajaxFunction()"/>
时间:<input type="text" name="time"/>
</form>
</body>
</html>
这是"time.asp"的代码:
<%
response.expires=-1
response.write(time)
%>
问题:time.asp(在最后)如果用php实现该用代码?请指教
运行您的AJAX应用程序
请在下面的文本框中键入一些文本,然后单击时间文本框:用户: 时间:
时间文本框可在不加载页面的情况下从"time.asp"获得服务器的时间!
//index.php
<html>
<head>
</head>
<body>
<script type="text/javascript">function ajaxFunction()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch(err)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
}
//Send
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.Open("GET","time.php",true);
xmlHttp.Send(null);
}</script>
<form name="My Form">
用户:<input type="text" name="userName" onkeyup="ajaxFunction()"/>
时间:<input type="text" name="time"/>
</form>
</body>
</html>
这是"time.asp"的代码:
<%
response.expires=-1
response.write(time)
%>
date_default_timezone_set('PRC');
echo date('l dS \of F Y h:i:s A');
?>date()函数的详细用法参看手册