通过Ajax实现的一个时钟_now.aspx是服务器反应的当前时间。
2010-03-18 17:15
190 查看
Ajax页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<****** type="text/javascript">
function doing()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch(e)
{
alert("您的浏览器不支持Ajax!");
return false;
}
}
}
xmlHttp .onreadystatechange = function ()
{
if (xmlHttp .readyState == 4)
{
var strResult = xmlHttp .responseText;
document .getElementById("now").value = strResult;
}
}
xmlHttp .open("GET","now.aspx",true);
xmlHttp .send(null);
}
function gettingTime()
{
setInterval(doing,1000);
}
</script>
</head>
<body onload ="gettingTime();" >
当前的系统时间:
<input type="text" id="now" >
</body>
</html> now.aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="now.aspx.cs" Inherits="now" %> now.aspx.cs页面: using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; public partial class now : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
Response.Write(DateTime .Now.ToString());
}
}
<head>
<title>Untitled Page</title>
<****** type="text/javascript">
function doing()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch(e)
{
alert("您的浏览器不支持Ajax!");
return false;
}
}
}
xmlHttp .onreadystatechange = function ()
{
if (xmlHttp .readyState == 4)
{
var strResult = xmlHttp .responseText;
document .getElementById("now").value = strResult;
}
}
xmlHttp .open("GET","now.aspx",true);
xmlHttp .send(null);
}
function gettingTime()
{
setInterval(doing,1000);
}
</script>
</head>
<body onload ="gettingTime();" >
当前的系统时间:
<input type="text" id="now" >
</body>
</html> now.aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="now.aspx.cs" Inherits="now" %> now.aspx.cs页面: using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; public partial class now : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
Response.Write(DateTime .Now.ToString());
}
}
相关文章推荐
- 十二、初学.NET—利用AJAX在页面头部显示服务器当前时间,并实现倒计时功能
- java实现一个小的时钟(当前时间)
- 利用头文件ctime,并且定义一个类,来实现输出当前时间
- js获得当前时间前后n天、n月、n年日期的一个简单实现
- Ajax显示当前时间(实现页面局部刷新)
- 一台linux服务器,通过apache实现,一个域名访问jsp的网站,一个域名访问php的网站
- 对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点;如果当前节点已经是该层的最后一个节点,则将pNext指针指向NULL;给出程序实现,并分析时间复杂度和空间复杂度。
- ajax获取服务器当前时间
- android应用实现自动升级从本地服务器,通过一个工具类
- JS实现Ajax---例:获取服务器时间
- 用Ajax实现获取服务器上的时间的简单的例子
- 在编辑框中动态显示当前时间,实现时钟功能
- 实现一个2008serve的IIS的虚拟目录(通过网络路径(UNC)的形式,共享在另外一个2008服务器上
- Go实战--实现一个并发时钟服务器(The way to go)
- [原创]利用php和javascript实现服务器时间电子时钟
- php获得可靠的精准的当前时间 ( 通过授时服务器 )
- Java设置session超时(失效)的时间 在一般系统登录后,都会设置一个当前session失效的时间,以确保在用户长时间不与服务器交互,自动退出登录,销毁session 具体设置的方法有三种:
- 实现一个用于显示当前时间的Google Android 窗口小部件(AppWidget)
- JAVA网络编程实现基于TCP协议的时间服务(向服务器查询当前时间)
- AJAX获取服务器当前时间