AJAX Forums

Simple function -sintaxis?

This is a discussion on Simple function -sintaxis? within the AJAX Help forums, part of the Beginners AJAX category; Sorry! I posted this in the wrong forum, could some one move it? I'm working on my first AJAX application. I got some code from a book and I ...


Go Back   AJAX Forums > Beginners AJAX > AJAX Help

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

Sorry! I posted this in the wrong forum, could some one move it?

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!

Last edited by h4x0rmx; 08-13-2008 at 07:18 PM. Reason: make it simple
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 : URGENT: Modify existing 'order status' function by clarapyjama admin AJAX Freelance Jobs 0 09-25-2008 11:04 PM
AJAX Jobs : Enable jQuery History for jQuery Treeview + Modified Function by ineedsom admin AJAX Freelance Jobs 0 09-07-2008 06:49 AM
AJAX Jobs : Small website with search function (see PDF) by priv4te admin AJAX Freelance Jobs 0 08-23-2008 12:15 PM
Need help with small simple code roshanjonah AJAX Questions 0 07-15-2008 03:43 AM
javascript function mozopacity ????? going123sold JavaScript 0 06-24-2007 02:17 PM


All times are GMT -4. The time now is 05:19 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