DJ Zen Masta K Posted March 17, 2009 Share Posted March 17, 2009 i've googled this, and there seems to be many ways using different methods. what is the simplest method of auto refreshing a single div? i have a page that has content dynamically updated that occasionally times out. i used to just use an iframe on my main page and used a simple javascript on the page that is framed to update it. i'm wanting to move from transitional to strict, which does not support iframes, so i've redeisgned the page to only use divs. Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/ Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 AJAX. an easy way is to get jQuery, and then use the load() method like so: $('#id_of_the_div').load('page.php'); that will get the contents of page.php and load it into the dom node with the ID of 'id_of_the_div'. as far as when that code gets executed...you can put it in a button, or inside setTimeout/setInterval to have it updated periodically Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/#findComment-786903 Share on other sites More sharing options...
DJ Zen Masta K Posted March 17, 2009 Author Share Posted March 17, 2009 thanks, i will have to see if my webhost supports jquery and learn it. in the meantime, i did find this code, but i can't get it to work: <html> <head> <script language="JavaScript" type="text/javascript"> function blah ( ) { var xmlhttp=false; try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } xmlhttp.open("GET", "songinfo.php", true); xmlhttp.onreadystatechange = function ( ) { if ( ajax.readyState == 4 ) { document.getElementById('songinfo').innerHTML = xmlhttp.responseText; } }; return; } setInterval('blah()', 10000); </script> </head> <body> <div id="songinfo"> <?php include ("songinfo.php"); ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/#findComment-787182 Share on other sites More sharing options...
DJ Zen Masta K Posted March 18, 2009 Author Share Posted March 18, 2009 this may belong in ajax help at this point. could a mod please move it there? Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/#findComment-787286 Share on other sites More sharing options...
rhodesa Posted March 18, 2009 Share Posted March 18, 2009 you were missing one part: <html> <head> <script language="JavaScript" type="text/javascript"> var xmlhttp; function blah ( ) { try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } xmlhttp.open("GET", "songinfo.php", true); xmlhttp.onreadystatechange = function ( ) { if ( xmlhttp.readyState == 4 ) { document.getElementById('songinfo').innerHTML = xmlhttp.responseText; } }; xmlhttp.send(null); return; } setInterval('blah()', 10000); </script> </head> <body> <div id="songinfo"> <?php include ("songinfo.php"); ?> </div> </body> </html> or with jQuery: <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> setInterval("$('#songinfo').load('songinfo.php');", 10000); </script> </head> <body> <div id="songinfo"> <?php include ("songinfo.php"); ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/#findComment-787951 Share on other sites More sharing options...
DJ Zen Masta K Posted March 19, 2009 Author Share Posted March 19, 2009 i should have listened to you to begin with. the jquery code works perfect. thanks!!!!! Link to comment https://forums.phpfreaks.com/topic/149848-solved-auto-refresh-single-div/#findComment-788158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.