User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,433 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,660 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1186 | Replies: 3
Reply
Join Date: May 2008
Posts: 14
Reputation: luxmi_gee is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
luxmi_gee luxmi_gee is offline Offline
Newbie Poster

refresh

  #1  
May 26th, 2008
hi

i want refresh the jsp page every seconds using AJAX in script.

any one have a code for that.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Noida, India
Posts: 158
Reputation: Luckychap is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 17
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Junior Poster

Re: refresh

  #2  
May 26th, 2008
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)
Last edited by Luckychap : May 26th, 2008 at 7:43 am.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote  
Join Date: May 2008
Posts: 14
Reputation: luxmi_gee is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
luxmi_gee luxmi_gee is offline Offline
Newbie Poster

Re: refresh

  #3  
May 26th, 2008
Originally Posted by Luckychap View Post
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.

  1. <html>
  2. <head>
  3. <script>
  4. function loadXMLDoc(url)
  5. {
  6. // code for Mozilla, etc.
  7. if (window.XMLHttpRequest)
  8. {
  9. xmlhttp=new XMLHttpRequest()
  10. xmlhttp.Open("GET","index.jsp",true)
  11. xmlhttp.Send(null)
  12. xmlhttp.onreadystatechange=state_Change
  13. }
  14. // code for IE
  15. else if (window.ActiveXObject)
  16. {
  17. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  18. if (xmlhttp)
  19. {
  20. xmlhttp.open("GET","index.jsp",true)
  21. xmlhttp.Send()
  22. xmlhttp.onreadystatechange=state_Change
  23. }
  24. }
  25. }
  26.  
  27. function init() {
  28. window.setTimeout( "loadXMLDoc( \"index.jsp\" );", 1 );
  29. // OR
  30. // window.setTimeout( "loadXMLDoc( \"page.php?req=true\" );", 3000 );
  31. }
  32. </script>
  33. </head>
  34. <body onload="init();">
  35. <div>
  36. <tlds:first bgColor="#385CA8" color="WHITE" fontSize="12"
  37. dateColor="yellow" width="1398" fontList="Arial"
  38. latitudeDeg="12" latitudeN="58" longitudeDeg="77"
  39. longitudeN="38" align="Center" >
  40. LEMS
  41. </tlds:first>
  42. </div>
  43. </body>
  44. </html>
Last edited by peter_budo : May 31st, 2008 at 6:12 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Mar 2008
Posts: 117
Reputation: Thirusha is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 13
Thirusha Thirusha is offline Offline
Junior Poster

Re: refresh

  #4  
May 27th, 2008
// 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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC