AJAX Forums

Simple modification needed

This is a discussion on Simple modification needed within the AJAX Questions forums, part of the Beginners AJAX category; I'm working on my first AJAX application. I got some code from a book and I edited it a little bit for my purposes: Code: window.onload=function(){ setTimeout('...


Go Back   AJAX Forums > Beginners AJAX > AJAX Questions

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Old 08-13-2008, 07:20 PM   #1 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 3
Rep Power: 0 h4x0rmx is on a distinguished road
Question Simple modification needed

I'm working on my first AJAX application. I got some code from a book and I edited it a little bit for my purposes:

Code:
window.onload=function(){
	setTimeout('process("inner.php")',1000);
}
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
	var xmlHttp;
	try{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
	    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
	                                    "MSXML2.XMLHTTP.5.0",
	                                    "MSXML2.XMLHTTP.4.0",
	                                    "MSXML2.XMLHTTP.3.0",
	                                    "MSXML2.XMLHTTP",
	                                    "Microsoft.XMLHTTP");
		for(var i=0; i<XmlHttpVersions.lenght && !xmlHttp; i++){
		    try{
		        xmlHttp = new ActivexObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp){
	    alert("Error creating the XMLHttpRequest object");
	}else{
	    return xmlHttp;
	}
}
function process(phpPage){
	if(xmlHttp){
		try{
		    xmlHttp.open("GET", phpPage, true);
		    xmlHttp.onreadystatechange = handleRequestStateChange;
		    xmlHttp.send(null);
		}
		catch(e){
		    alert("Can't connect to server:\n" + e.toString());
		}
	}
}
function handleRequestStateChange(){
	myDiv = document.getElementById("myDivElement");
 	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
	        try{
	            response = xmlHttp.responseText;
	            myDiv.innerHTML = response;
	            setTimeout('process("inner.php")',1000);
			}catch(e){
		    	alert("Error reading the response: " + e.toString());
			}
	}else if(xmlHttp.readyState < 0 || xmlHttp.readyState > 4){
	    alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
 	}
}
The code as it is will refresh a <div> with the id "myDivElement" with the contents of "inner.php".
What I want to do is to have a generic code/function that will accept (1)the ID of my Div, (2)the page (php) that it should load into the div, and (3)the time that it should wait between refreshes. (I'm having different sections of the page that need to be reloaded every n seconds). It seems to me that it could be done pretty easy, but I have no idea how to do it.
Anyone could help?
I will really appreciate it!
h4x0rmx is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
AJAX Jobs : Simple Digg Bot Needed by seodigital admin AJAX Freelance Jobs 0 09-08-2008 09:54 AM
AJAX Jobs : Simple Site + Script Modification by cartelinc admin AJAX Freelance Jobs 0 07-06-2008 05:49 AM
AJAX Jobs : Simple form needed by comcast admin AJAX Freelance Jobs 0 07-04-2008 11:18 AM
AJAX Jobs : Simple PHPProBid add-on needed by painterj admin AJAX Freelance Jobs 0 06-09-2008 07:25 PM
AJAX Jobs : Simple PHPProBid interface add-on needed by painterj admin AJAX Freelance Jobs 0 06-09-2008 08:02 AM


All times are GMT -4. The time now is 06:10 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5
Copyright ©2006 - 2008, AJAXwith.com