tinman486 Posted August 7, 2008 Share Posted August 7, 2008 I am trying to load an external file into a div on my site. The file is on my server. My function function ahah(url, target) { document.getElementById(target).innerHTML = ' Fetching data...'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req != undefined) { req.onreadystatechange = function() {ahahDone(url, target);}; req.open("GET", url, true); req.send(""); } } function ahahDone(url, target) { if (req.readyState == 4) { // only if req is "loaded" if (req.status == 200) { // only if "OK" document.getElementById(reportspace).innerHTML = req.responseText; } else { document.getElementById(reportspace).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText; } } } function load(name, div) { ahah(name,div); return false; } should grab the url from the link on click and put it into the Div at the bottom of this page <html> <head> <Meta author="Justin England"> <script src="ajax.js"></script> </head> <body> <form> Select A Report: <a href="page.html" onclick="load('file1.html','content');return false;">File 1</a> </select> </form><p> <div id="reportspace"><b>Report info will be listed here.</b></div> </p></body> </html> however it simply links to the page I have a feeling my code isn't being executed which to be honest is the only real reason for this issue. Any suggestions on changes? What am i missing? Also If anyone could tell me how to do this same operation but with a drop down menu where the div displays pages based on the choices selected from the menu if that is even possible. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted August 7, 2008 Share Posted August 7, 2008 HTML/Javascript <script type="text/javascript"> function getfile() { var req; req = new XMLHTTPRequest(); req.onreadystatechange = function() { if (req.readyState==4) { document.getElementById('div').innerHTML=req.responseText; } } req.open("GET","file.php?file="+document.getElementById('file').value,true); req.send(null); } </script> File: <input type="text" id="file" /><br /> <div id="div"></div> PHP <?php header( 'Cache-Control: no-cache, must-revalidate' ); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); print nl2br( htmlentities( file_get_contents( $_GET['file'] ), ENT_QUOTES ) ); ?> Quote Link to comment Share on other sites More sharing options...
tinman486 Posted August 8, 2008 Author Share Posted August 8, 2008 alrighty, what does the php script do? Thanks for the help I think I get what your doing perhaps a comment or two? Quote Link to comment Share on other sites More sharing options...
dbertels Posted August 8, 2008 Share Posted August 8, 2008 See my reply at http://www.phpfreaks.com/forums/index.php/topic,209702.msg960110.html#msg960110 Does this answer your problem? Quote Link to comment Share on other sites More sharing options...
corbin Posted August 9, 2008 Share Posted August 9, 2008 If you're wondering what was wrong with your original script, I suspect it had to do with variable scope. Google it if you want. 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.