Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

passing an array of functions as an argument

Avatar of walkman69
walkman69 asked on
JavaScriptAJAX
2 Comments1 Solution233 ViewsLast Modified:
Hi guys.

I have made something like this:


function init()
{
	var gnu = [init_function_01(), init_function_02()];
	ajax_get_page("some_page_01.php", "", "content_center", gnu);
}

function init_function_01() {
	console.log("gnu1");
}

function init_function_02() {
	console.log("gnu2");
}

function ajax_get_page(page, arg, elem, init_functions) {
	
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {	
			document.getElementById(elem).innerHTML=xmlhttp.responseText;
			
			for(x = 0; x < init_function.length; x++) {
				init_functions[x];
			}
		}
	}
	
	xmlhttp.open("GET",page+arg,true);
	xmlhttp.send();	
}

The init-function is called on load.

So I try to get a page and place the output inside an HTML-element called content_center,
and if the page has been correctly loaded, a couple of functions are supposed to be called.
However.. this doesn't work since the functions are called on start. And then they aren't called at all.. I think I lack some knowledge here..

Anyone got a good solve for this?


ASKER CERTIFIED SOLUTION
Avatar of walkman69
walkman69

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers