Refreshing a div without page reload using Ajax:
This Ajax code will used to refresh a div element autometically in every 3 seconds with out page reload.
You can changed the refreshing time.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Auto Refresh</title>
<script type="text/javascript">
function AutoRefresh(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("No AJAX");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('AutoUpdte').innerHTML=xmlHttp.responseText;
setTimeout('AutoRefresh()',3000); // JavaScript function calls AutoRefresh() every 3 seconds
}
}
xmlHttp.open("GET","Your_page_url_that_contains_the_div_content",true);
xmlHttp.send(null);
}
AutoRefresh();
</script>
</head>
<body>
<div id="AutoUpdte">Your Content</div>
</body>
</html>
Enjoy!
Subscribe to:
Post Comments (Atom)
0 comments
Post a Comment