/    Sign up×
Community /Pin to ProfileBookmark

Refresh one div?

Hello

I have seen some of these posts on the forum, but they seem to contain other code such as refreshing a song title or such

All we basically want is for a <div id=”new”> .. </div> block to refresh every 10 minutes automatically, without disturbing the rest of the page. So if someone was on the page typing something, it wouldn’t even affect that…

Is this possible?

Thank you

to post a comment
HTML

6 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMar 14.2008 — Assuming a function getNewData returns the items to be refreshed:
<i>
</i>function reload(){
var newInput=getNewData();
document.getElementById("new").innerHTML=newInput;
setTimeout("reload()",600000);
}
window.onload = reload;
Copy linkTweet thisAlerts:
@DanUKauthorMar 14.2008 — Hi there, thank you for that ?

Is the "getNewData();" part required?

I'm not sure if this will work as it's for a PHP thing... basically in our 'new' div I will put a PHP script which checks for new messages or support tickets. If there's new ones, it starts flashing...

Will this operate correctly by loading that PHP too?

Hope that makes sense
Copy linkTweet thisAlerts:
@TheBearMayMar 14.2008 — The getNewData is a placeholder for for data retrieval routine. I'll have to play a little to see if I can construct something that will work with PHP in the background without resending the entire page...
Copy linkTweet thisAlerts:
@ray326Mar 14.2008 — What you're looking for is AJAX, Dan.
Copy linkTweet thisAlerts:
@TheBearMayMar 14.2008 — Quick demo for you:
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>PHP AJAX</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getHTTPObject(){
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}

var inc=0;
function callPHP(){
inc++;
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "phpAjax.php?phraseNum="+inc, true);
httpObject.send(null);
httpObject.onreadystatechange = setDiv;
}
setTimeout("callPHP()", 5000);
}

function setDiv(){
if(httpObject.readyState == 4){
document.getElementById('oPut').innerHTML = httpObject.responseText;
}
}

window.onload=callPHP;

</script>
</head>

<body>

<textarea></textarea>
<div id="oPut"></div>
</body>
</html>[/code]

[code=php]<?php
if (isset($_GET["phraseNum"]))
echo "Phrase ".$_GET["phraseNum"];
else
echo "Return from PHP";
?>[/code]
Copy linkTweet thisAlerts:
@DanUKauthorMar 14.2008 — Just wanted to say Thank you for the help, I'll give it a shot tomorrow when my FTP begins working again!!! ?
×

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...