PDA

View Full Version : Refreshing Multiple Divs Ajax HELP!



paulupnorth
07-13-2012, 11:20 AM
Hi Guys and Gals,

Thanks for taking your time to have a look.

I am using this:



<script type="text/javascript">

function Ajax()
{
var
$http,
$self = arguments.callee;

if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
}
}

if ($http) {
$http.onreadystatechange = function()
{
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('refreshthis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 5000);
}

};
$http.open('GET', 'test.asp' , true);
$http.send(null);
}


}


</script>


<script type="text/javascript">
setTimeout(function() {Ajax();}, 5000);
</script>


To refresh a div on my page called refreshthis, I would like to refresh multiple divs on the same page (refreshthis and refreshthis2) but my attempts have failed miserably.

Thanks for your time and any help in advance!

jscheuer1
07-13-2012, 04:45 PM
Well, if that works for one, this should work for two:


<script type="text/javascript">
function Ajax(url, id){
var $http = null;

if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {$http = new ActiveXObject('Microsoft.XMLHTTP');} catch(e){$http = null;}
}
}

if ($http) {
$http.onreadystatechange = function(){
if (/4|^complete$/.test($http.readyState)) {
document.getElementById(id).innerHTML = $http.responseText;
}
};
$http.open('GET', url + '?bustcache=' + new Date().getTime(), true);
$http.send(null);
}

}
</script>
<div id="refreshthis"></div>
<div id="refreshthis2"></div>
<script type="text/javascript">
setInterval(function(){Ajax('test.asp', 'refreshthis');}, 5000);
setInterval(function(){Ajax('test2.asp', 'refreshthis2');}, 5000);
</script>