w3schools Logo
Monday 21 May 2012
W3schools.in Developer Network

AJAX Basic

AJAX Introduction AJAX Examples

AJAX XMLHttpRequest

Create an XMLHttpRequest Object Send a Request To a Server Server Response The onreadystatechange Event

AJAX Advanced

AJAX PHP Example AJAX PHP with MySql Database AJAX XML File



AJAX Function
2010-09-14 09:09:59 614day

<div id="pic"> </div>


<script type="text/javascript">
function handleHttpResponse() {
    
if (http.readyState == 4) {

var results=http.responseText;

document.getElementById("pic").innerHTML=results;

setTimeout("AjaxFunction()",3000);
}


}



function AjaxFunction() {
var page="page.php"+"?random="+Math.random();
http.open("GET", page, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}




function getHTTPObject() {
var xmlhttp;

if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}

}
return xmlhttp;


}
var http = getHTTPObject(); // We create the HTTP Object

AjaxFunction();

</script>

 

Anand
2011-02-03 23:02:45 472day

very helpful for those who new in ajax........

 


Add Comments / Scripts
Name:
E-mail:
Comment:
 


Can't read the image? click here to refresh