hi
i want refresh the jsp page every seconds using AJAX in script.
any one have a code for that.
hi
i want refresh the jsp page every seconds using AJAX in script.
any one have a code for that.
First I want to tell u if u want the whole page to refresh, then there is no need to use ajax. U just have to write a function which will load ur page every pireod of time..
Ajax is used to update small portion of the page in background without waiting for hole page to get refresh. You can use ajax to make ur page user-intractive, by peforming some small task in the backgound while the user is free to intract with the page.
Best example is: there is web page to display weather reports of various cities, and if user selects a city, the weather details corresponding to that city should be loaded in a div.
And here is where the real power of ajax comes. You can creata function which send an ajax request and get the weather details from server back to client, and according to data u can update the div with new value (Temp, images etc.) without refreshing the whole page. And what more, a second request is generated a regular interval to update the current temp of ur current location. in this way so many changes are going on the page without refreshing full page. And user also get a good feeling.(who wants to wait for whole page to load again)
First I want to tell u if u want the whole page to refresh, then there is no need to use ajax. U just have to write a function which will load ur page every pireod of time..
Ajax is used to update small portion of the page in background without waiting for hole page to get refresh. You can use ajax to make ur page user-intractive, by peforming some small task in the backgound while the user is free to intract with the page.
Best example is: there is web page to display weather reports of various cities, and if user selects a city, the weather details corresponding to that city should be loaded in a div.
And here is where the real power of ajax comes. You can creata function which send an ajax request and get the weather details from server back to client, and according to data u can update the div with new value (Temp, images etc.) without refreshing the whole page. And what more, a second request is generated a regular interval to update the current temp of ur current location. in this way so many changes are going on the page without refreshing full page. And user also get a good feeling.(who wants to wait for whole page to load again)
thanks for your reply
here i paste my coding, but it has some error.
i don't where is the mistake.
cna you help me to sole that.
<html>
<head>
<script>
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.Open("GET","index.jsp",true)
xmlhttp.Send(null)
xmlhttp.onreadystatechange=state_Change
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.open("GET","index.jsp",true)
xmlhttp.Send()
xmlhttp.onreadystatechange=state_Change
}
}
}
function init() {
window.setTimeout( "loadXMLDoc( \"index.jsp\" );", 1 );
// OR
// window.setTimeout( "loadXMLDoc( \"page.php?req=true\" );", 3000 );
}
</script>
</head>
<body onload="init();">
<div>
<tlds:first bgColor="#385CA8" color="WHITE" fontSize="12"
dateColor="yellow" width="1398" fontList="Arial"
latitudeDeg="12" latitudeN="58" longitudeDeg="77"
longitudeN="38" align="Center" >
LEMS
</tlds:first>
</div>
</body>
</html>
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.Open("GET","index.jsp",true)
xmlhttp.Send(null)
xmlhttp.onreadystatechange=state_Change
}
should be
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.open("GET","index.jsp",true)
xmlhttp.send(null)
xmlhttp.onreadystatechange=state_Change
}
U were using captial letters for open and send
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.