Results 1 to 2 of 2

Thread: Refreshing Multiple Divs Ajax HELP!

  1. #1
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Refreshing Multiple Divs Ajax HELP!

    Hi Guys and Gals,

    Thanks for taking your time to have a look.

    I am using this:

    Code:
     <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!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, if that works for one, this should work for two:

    Code:
    <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>
    Last edited by jscheuer1; 07-13-2012 at 04:57 PM. Reason: spacing
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    paulupnorth (07-17-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •