PDA

View Full Version : Refreshing DIV



PixelWill
26-04-2008, 04:38 PM
Hey all, I've tried look for AJAX page refresh's, AJAX page fetchers, but strangely enough, nothing meets my requirements.. It's not to say I haven't found anything what so ever. I have actually found some things but don't do what I want though.

I'm looking for a simple refresh that obviously doesn't refresh the whole page, but just refresh's a single DIV.

Does anyone know how I would go about it and where I could perhaps find one?

Thanks..

L?KE
26-04-2008, 04:44 PM
Use an iframe?

Or pay some javascript wizz to do something in ajax for you.

PixelWill
26-04-2008, 04:49 PM
I considered an iframe, but I didn't want the browser ticking all the time.

Agnostic Bear
26-04-2008, 05:01 PM
function start_div_update( )
{
setInterval("change_page('div name', 'file name', 'any variables')", 10000);
// Change every 10 seconds (time you want x 1000) ---------------------^
}
function GetXmlHttpObject( )
{
var objXMLHttp = null
if ( window.XMLHttpRequest )
{
objXMLHttp = new XMLHttpRequest( );
}
else if ( window.ActiveXObject )
{
// Haha oh wow, I got this from Wikipedia of all places.
objXMLHttp = function(){
try { return new ActiveXObject( "MSXML3.XMLHTTP" ); } catch( e ) { }
try { return new ActiveXObject( "MSXML2.XMLHTTP.3.0" ); } catch( e ) { }
try { return new ActiveXObject( "Msxml2.XMLHTTP" ); } catch( e ) { }
try { return new ActiveXObject( "Microsoft.XMLHTTP" ); } catch( e ) { }
throw new Error( "Could not find an XMLHttpRequest alternative. Please upgrade your browser or allow ActiveX Objects if you are using Internet Explorer." );
};
}
return objXMLHttp;
}
function change_page( element, TheUrl, TheVars )
{
xmlHttp = GetXmlHttpObject( )
if ( xmlHttp == null )
{
alert( "Your browser is either outdated or you have xmlHttp disabled, please upgrade your browser or enable xmlHttp requests." );
return;
}
var url = TheUrl + "?" + TheVars + "&" + Math.random();
//alert(url)
xmlHttp.open( "GET", url ,true );
xmlHttp.onreadystatechange = function ( )
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
document.getElementById( element ).innerHTML = xmlHttp.responseText;
}
}
};
xmlHttp.send( null );
}

PixelWill
26-04-2008, 05:32 PM
Oh thanks, I'll try it out.

PixelWill
26-04-2008, 06:01 PM
Sorry for double post, but couldn't edit.

Is it the just bits marked at the top I change because it doesn't seem to be working..

I've put it in <script></script> tags, but it doesn't do anything. :S

L?KE
26-04-2008, 10:26 PM
Could you not use javascript to define an area, then use execCommand('Refresh', false, null); to refresh that area?



<html>
<head>
<script type="Javascript">

function start() {
divname.document.designmode = 'on';
}

function refresh() {
divname.document.execCommand('refresh', false, null);
}

</script>
</head>
<body onload="start()">

<div id="divname" onclick="refresh()"></div>

</body>
</html>


Not entirely sure that would work, but just a suggestion :)

PixelWill
27-04-2008, 09:51 AM
I could probably try tht yeah.. I hardly know Javascript, but I could probably mess around with it..

Thanks!

PixelWill
27-04-2008, 10:51 AM
Sorry for double post, couldn't edit.

It does work, but.. I wanted it to refresh a DIV on it's on eveyr so many seconds.. where would I put an setInterval thing or whatever it's called?

Want to hide these adverts? Register an account for free!