DjNaF Posted December 8, 2006 Share Posted December 8, 2006 hello;i have got ajax function that load data into div, 3 functions with 3 divsnow i want to call those functions when page loadsi'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 Quote Link to comment Share on other sites More sharing options...
tomfmason Posted December 8, 2006 Share Posted December 8, 2006 Just write another function and call the other three functions from it..Example[code]function pageLoad() { function1(ar); function2(ar); function3(ar);}[/code]now onload="loadPage();"Good Luck,Tom Quote Link to comment Share on other sites More sharing options...
DjNaF Posted December 9, 2006 Author Share Posted December 9, 2006 i tried it same thing :( Quote Link to comment Share on other sites More sharing options...
artacus Posted December 9, 2006 Share Posted December 9, 2006 It SHOULD work. I do this often. What happens when you reverse the order?My guess is the problem lies with your actual AJAX calls. Quote Link to comment Share on other sites More sharing options...
DjNaF Posted December 9, 2006 Author Share Posted December 9, 2006 [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 Quote Link to comment Share on other sites More sharing options...
alpine Posted December 9, 2006 Share Posted December 9, 2006 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] Quote Link to comment Share on other sites More sharing options...
DjNaF Posted December 9, 2006 Author Share Posted December 9, 2006 it's not working :(it loads yourAjax('1') onlyand 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! Quote Link to comment Share on other sites More sharing options...
DjNaF Posted December 9, 2006 Author Share Posted December 9, 2006 :) wow at last after thinking in a tricky way i found a devils solutioni 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 limitationi hope it will be useful for you allthank you Quote Link to comment Share on other sites More sharing options...
alpine Posted December 9, 2006 Share Posted December 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
DjNaF Posted December 9, 2006 Author Share Posted December 9, 2006 do you have another solutions other than mine? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.