Jump to content

OnLoad problem with mulitple ajax functions


DjNaF

Recommended Posts

hello;

i have got ajax function that load data into div, 3 functions with 3 divs
now i want to call those functions when page loads

i've tried onload="function1(rr);function2(rr);function3(rr);"

but the only function that works really is Function3 , the last one called!

i want the 3 function to work! anyone got an idea?

Thank you
Link to comment
Share on other sites

[code]
function ajaximusic(id){

var url = "page.php?id="+id;
//alert (url);
try{ Answer = new XMLHttpRequest();
}catch(error){
try{
Answer = new ActiveXObject("Microsoft.XMLHTTP");
}catch(error){ Answer = null; return false;
}
}
Answer.onreadystatechange = change_rests_infoo3;
Answer.open("POST", url);
Answer.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Answer.send(null);
}

function change_rests_infoo3(){
if (Answer.readyState == 4){
if(Answer.status == 200){
document.getElementById('rests3').innerHTML = Answer.responseText;
}
}

}

[/code]

i have 3 functions like the above but everyone with different

document.getElementById('rests3').innerHTML

when i change order , it apply only the last one
Link to comment
Share on other sites

Try the addEvent (http://www.scottandrew.com/weblog/articles/cbs-events)

[code]

function addEvent( obj, type, fn )
{
if (obj.addEventListener)
obj.addEventListener( type, fn, false );
else if (obj.attachEvent)
{
obj["e" + type + fn] = fn;
obj.attachEvent( "on" + type, function(){ obj["e" + type + fn](); } );
}
}

addEvent(window,"load", function(){ yourAjax('1') });
addEvent(window,"load", function(){ yourAjax('2') });
addEvent(window,"load", function(){ yourAjax('3') });

[/code]
Link to comment
Share on other sites

it's not working :(
it loads yourAjax('1') only
and when i refresh the page sometimes it loads yourAjax('1') in 2 divs! not one!
the div that is supposed to be for function1() and the div for function2();

i dont know why!

please i need help in this it's driving me crazy!
Link to comment
Share on other sites

:) wow at last after thinking in a tricky way i found a devils solution
i used thin in body onLoad="setTimeout('call2()',500);setTimeout('call()',1000);setTimeout('call3()',1500);"

i gave some time between calling the functions so by this it will break the onload limitation

i hope it will be useful for you all

thank you
Link to comment
Share on other sites

well, if you create 3 separate xmlhttp requests (one inside each ajaxfunction) your timeout can be prevented and everything loads simultaniously. I was under the impression that you already had 3 different functions with 3 dedicated xmlhttp.

Let's say you have slow server responce on the first call, the next one will overwrite and you will still get into the same problems as the ones you had before.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.