<script type="text/javascript" language="javascript">
var xmlHttpRequest;
function GetCurTime() {
//create XMLHttpRequest object
xmlHttpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
//browser doesn’t support Ajax,so exit
if (xmlHttpRequest == null)
return;
//Init XMLHttpRequest object
xmlHttpRequest.open("POST", "http://localhost/Jquery/Ajax/TimeAjaxTest.aspx", true);
//callback function setting
xmlHttpRequest.onreadystatechange = StateChange;
xmlHttpRequest.send(null);
}
function StateChange() {
if (xmlHttpRequest.readyState == 4) {
alert(xmlHttpRequest.responseText);
document.getElementById('lblTime').value = xmlHttpRequest.responseText;
}
}
</script>
in page -
<a onclick="GetCurTime();">Ajax test by normal javascript</a> <input id="lblTime"/>
here i posted to TimeAjaxTest.aspx page.in that page's code behind file put this
in Page Load method -
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second);
}