Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Refreshing a div through javascript (Ajax)
Old 09-25-2009, 10:48 AM Refreshing a div through javascript (Ajax)
Novice Talker

Posts: 11
Name: Robert Gouveia
Trades: 0
Hi everyone i am new to javascripting and ajax.

I was wonding if you guys can help me with something.

Basically ive got a socialengine script like facebook.

In the feed which posts what everyone is doing i would like that div which is called
HTML Code:
<div id ="userhomerefresher"></div>
How do i make it so that div refreshes every 5 seconds.

I have tried to do it like this

HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test code</title>
<script type="text/javascript" src="js/autorefresher.js"></script>
</head>

<body>

<div id="userhomerefresher"></div>
</body>
</html>
And i have a js file which is coded like this:

HTML Code:
// JavaScript Document

function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.open("GET",url,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",url,true)
    xmlhttp.send()
    xmlhttp.onreadystatechange=state_Change
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
      if (xmlhttp.status==200)
      {
      document.getElementById('userhomerefresher').innerHTML=xmlhttp.responseText;
      }
  }
  
}

function init() {
window.setTimeout( "loadXMLDoc( \"other_doc.html\" );", 5000 );
// OR
// window.setTimeout( "loadXMLDoc( \"page.php?req=true\" );", 5000 );
}
This unfortunatly doesnt work.

Can someone help me and please bare in mind i am very very new to javascripting.

Thanks

Robert
RobbieG is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-25-2009, 10:52 AM Re: Refreshing a div through javascript (Ajax)
Novice Talker

Posts: 11
Name: Robert Gouveia
Trades: 0
i got this script from someone but as i can see it is not exactly the thing i need. I dont need it to refresh to a html i just need to refresh full stop.

Thanks

Robert
RobbieG is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Refreshing a div through javascript (Ajax)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10358 seconds with 12 queries