Saturday, 02 February 2013 13:55

how to implement ajax in web page

Written by 
Rate this item
(0 votes)

Today ajax is being a common part in most large website and
application.user loves the way everything done without page
refresh and website's with ajax implemented is getting higher the following i showed how to use ajax in
web can use in php too -

in head section -

<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)

//Init XMLHttpRequest object"POST", "http://localhost/Jquery/Ajax/TimeAjaxTest.aspx", true);

//callback function setting
xmlHttpRequest.onreadystatechange = StateChange;

function StateChange() {

if (xmlHttpRequest.readyState == 4) {
document.getElementById('lblTime').value = xmlHttpRequest.responseText;


in page -

<a onclick="GetCurTime();">Ajax test by normal javascript</a> <input id="lblTime"/>

here i posted to TimeAjaxTest.aspx 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);

Read 3236 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.