Hi,
Did you still set response.expire=-1 in .ashx file? Actually, it needn't. It will ouput the newest DateTime on server with the below code.
In ashx file, we can use context.Response.Write rather than just Response.Write.
time1.ashx:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write(DateTime.Now.ToString());
}
}
And you can use xmlhttprequest to retrieve the data.
vvar XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}
function GetTime()
{
var url="time1.ashx";
var xmlhttp = createXMLHTTPObject();;
xmlhttp.open("GET", url,true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
var responsetext=xmlhttp.responseText;
document.getElementById('timetext').value=responsetext;
}
}
xmlhttp.send(null);
}
<input id="timetext" type="text" />