Hi,
I was working with an AJAX test page and having some problems with a DOM loading routine I've tried. The scenario is something like this.
There are 3 pages involved in this. The first page issues an AJAX request to the second page. The second page has some div elements and an iframe which loads the 3rd page. The 3rd page has nothing but a script section in which I've declared a JS variable.
In other words the result of the AJAX call will be the content of 2nd page which will be put into a div element in page 1 using innerHTML, which in turn will load the 3rd page via iframe. What I am trying to do is after loaidng the 3rd page in the div container I accessed the JS variable that I declared from the first page successfully. After I've removed the div content (the 3rd page contents from the div) and then loaded the DOM again in the div and tried to access the JS variable again and found that it has a value undefined.
I am able to get the JS variable value correctly even after the 2nd reloading of DOM when I call location.reload(). But I am looking if this can be done without the reloading of the page in either way (from cache or from server).
You can see my code below
Code:Filename : 1.htm <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Untitled Document</title> <script type="text/javascript" src="yahoo-min.js"></script> <script type="text/javascript" src="event-min.js"></script> <script type="text/javascript" src="connection-min.js"></script> <script type="text/javascript"> var handleSuccess = function(o){ document.getElementById('container').innerHTML = o.responseText; } var handleFailure = function(o){ alert('ajax call failed'); } var callback = { success:handleSuccess, failure:handleFailure }; var sUrl = "2.htm"; function makeRequest(){ var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); } function removeDom(){ document.getElementById('container').innerHTML = ''; location.reload(false); } function detectEdObj(){ alert(window.frames['iframe_EDITR'].k); } </script> </head> <body> <div id="container"> </div> <br><br> <form> <input type="button" onclick="javascript: makeRequest();" value="load dom"><input type="button" onclick="javascript: removeDom();" value="remove dom"> <input type="button" onclick="javascript: detectEdObj();" value="Detect JS Variable"> </form> </body> </html>Code:Filename : 2.html <div id="EDITR"> <form> <iframe name="iframe_EDITR" width="784" height="10" frameborder="0" src="3.htm"></iframe> </form> </div>Let me know if you need any more information about this. You can find my test files as attachment. Put all the files in the same folder and view 1.htm first click 'load dom' button then "Detect JS Variable" button then 'remove dom' button. Then again 'load dom' button and "Detect JS Variable" where you can see the problem. The aim is If it is possible I would like to get the variable values after the reloading without doing a whole page reload.Code:Filename : 3.htm <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Untitled Document</title> <script type="text/javascript"> var k = 99; </script> </head> <body> </body> </html>
In my case I've accessed these files through my web server
Regards
Codex



Reply With Quote
. Anyway this one seems to be an interesting problem..

Bookmarks