mysterbx Posted July 31, 2008 Share Posted July 31, 2008 Hello, im using the script from http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm and i cant figure how to know if my script (its below) is loaded... i started using javascripts only a week ago, and im not so good at it, so please help me out! function loadit() { ajaxpage('test1.htm', 'contentarea1'); ajaxpage('test2.htm', 'contentarea2)'; ajaxpage('test3.htm', 'contentarea3'); } so ho dow i know when "loadit" function is finished the work? its the last component to my search engine Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 31, 2008 Share Posted July 31, 2008 Add an alert in the function and you will know. function loadit() { ajaxpage('test1.htm', 'contentarea1'); ajaxpage('test2.htm', 'contentarea2)'; ajaxpage('test3.htm', 'contentarea3'); alert('done'); } Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 1, 2008 Author Share Posted August 1, 2008 well, its not that simple... the script is ajax, and the function above will only load everything at the time, i need a script that would know when the ajax script's were finieshed loading Quote Link to comment Share on other sites More sharing options...
xenophobia Posted August 1, 2008 Share Posted August 1, 2008 Your ajaxpage function, does it had callback function when the ajax returned the value. Like: if(httpRequest.readyState == 4) { // Done~ } If it does, it might look something like: function loadit() { ajaxpage('test1.html', 'contentarea1', callback); ajaxpage('test2.html', 'contentarea2', callback); ajaxpage('test3.html', 'contentarea3', callback); } var readyPage = 0; function callback() { readyPage ++; if(readyPage >= 4) { // Here you know your function is totally completely run } } There is no direct code for this purpose. You had to use event handler to capture it. Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 1, 2008 Author Share Posted August 1, 2008 yes, ti has the function if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) { but still nothing shows up (the should be an alert) here is my full test page source: <script type='text/javascript' src='images/b0.js'></script> <script> function loadit() { mysterbx('2.php', 'x', callback); mysterbx('2.php', 'z', callback); mysterbx('2.php', 'c', callback); } var readyPage = 0; function callback() { readyPage ++; if(readyPage >= 4) { alert('done'); } } </script> <div id='x'></div> <div id='z'></div> <div id='c'></div> any ideas? Quote Link to comment Share on other sites More sharing options...
xenophobia Posted August 1, 2008 Share Posted August 1, 2008 Sorry, it should be more than equal to 3. if(readyPage >= 3) { alert('done'); } Also, are you sure that the callback function are called upon the ajax loaded the page? Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 1, 2008 Author Share Posted August 1, 2008 i changed the code, but still the same "nothing", i think the main script (ajax script) needs correction i will post the full page source + the main script, maybe it will be easier? 2.php: <script type='text/javascript' src='b0.js'></script> <script> function loadit() { mysterbx('2.php', 'x', callback); mysterbx('2.php', 'z', callback); mysterbx('2.php', 'c', callback); } var readyPage = 0; function callback() { readyPage ++; if(readyPage >= 3) { alert('done'); } } </script> <div id='x'></div> <div id='z'></div> <div id='c'></div> b0.js: var bustcachevar=1 var loadedobjects="" var rootdomain="http://"+window.location.hostname var bustcacheparameter="" function mysterbx(url, containerid, xload, xtype){ var page_request = false if(!xload) { loadingtext=""; } else { loadingtext=xload; } xxtype=xtype; if (window.XMLHttpRequest) page_request = new XMLHttpRequest() else if (window.ActiveXObject){ try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() page_request.open('GET', url+bustcacheparameter, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) { document.getElementById(containerid).innerHTML=page_request.responseText; return false; } else { document.getElementById(containerid).innerHTML = loadingtext; return false; } } and thanks a lot for helping, this is the last component of page, now its a little buggy, if everything works out fine, then a huge bug will be fixed, many users unhappy for it Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 1, 2008 Author Share Posted August 1, 2008 i just saw this: function mysterbx(url, containerid, xload, xtype){ thats why the script doesnt work, there are 4 values, the 5th should be "callback" i did this: function loadit() { mysterbx('2.php', 'x','','', callback); mysterbx('2.php', 'z','','', callback); mysterbx('2.php', 'c','','', callback); } .. but still nothing! Quote Link to comment Share on other sites More sharing options...
xenophobia Posted August 1, 2008 Share Posted August 1, 2008 In your myster function, modify a bit: page_request.onreadystatechange=function(){ loadpage(page_request, containerid) if(typeof(arguments[4]) == 'function') { arguments[4](); } } Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 1, 2008 Author Share Posted August 1, 2008 grrrr the same i dont know what im doing wrong... here is my test page: http://www.bxsearch.com/g.php and here is the script which we are trying to modify: http://www.bxsearch.com/b0.js Quote Link to comment Share on other sites More sharing options...
mysterbx Posted August 2, 2008 Author Share Posted August 2, 2008 help me out here... i need this script working so bad Quote Link to comment Share on other sites More sharing options...
xenophobia Posted August 2, 2008 Share Posted August 2, 2008 add my msn: xenophobia87@hotmail.com Maybe we can talk better in there. 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.