walkman69
asked on
passing an array of functions as an argument
Hi guys.
I have made something like this:
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var init_functions = [];
var elem = "";
We do a synchrone call : xmlhttp.open("GET", page + arg , false);
Open in new window