frankhaugen Posted January 15, 2011 Share Posted January 15, 2011 I'm new to AJAX so forgive me if I don't no the lingo fully. I am working on a website, I have turned to AJAX from iframes, and I've hit a snag, which maybe some of you can help me with. Using this code: <script class="AJAXscript" type="text/javascript"> function loadXMLDoc2() { 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("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","test.php",true); xmlhttp.send(); } </script> <button type="button" onclick="loadXMLDoc2()">hi</button> I open a php file, which in turn have links I need to use, using the "AJAX div element" it is inside of to present the second php document, but using the same code, of course with different names, it just isn't responsive. Any ideas?? Thanks for any help!! here are code in my test project I'm using to figure this out: index.php: <!DOCTYPE HTML> <html> <head> <title> Lorem ipsum dolor sit amet </title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> function loadXMLDoc() { 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("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","test2.php",true); xmlhttp.send(); } </script> </head> <body> <div id="wrapper"> <div id="banner"> </div> <div> <button type="button" onclick="loadXMLDoc()">Change Content</button> </div> <div> <div id="myDiv"><h2>Let AJAX change this text</h2></div> </div> <div></div> <div></div> </div> </body> </html> test2.php: <script class="AJAXscript" type="text/javascript"> function loadXMLDoc2() { 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("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","test3.php",true); xmlhttp.send(); } </script> <button type="button" onclick="loadXMLDoc2()">hi</button> test3.php: <?php echo "success"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/224484-opening-an-ajax-element-inside-an-ajax-element/ 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.