khadra4ever Posted January 13, 2011 Share Posted January 13, 2011 Hi guys! I have a form with a button and a textarea, when i click on the button it opens a text file and displays its content in the textarea the problem is when i update the file and click the button the changes i made to the file don't show in the textarea, it only shows the old content. here's my code <script type="text/javascript"> var req; var FileName="http://localhost/file.txt"; function OpenFile(url) { req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } if(req) { req.onreadystatechange = processReqChange; req.open("GET", url, true);; req.send(""); } } function processReqChange() { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('txtOutput').value=req.responseText; } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } } </script> <input type="button" id="btnOpen" value="Open File" onClick="OpenFile(FileName)" /><br /> <textarea id='txtOutput' rows='20' cols='100'></textarea> //----------------------------------------------End code-------------------------------------------------------------------------- Can anybody tell me if anything wrong in my code Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/224305-open-a-text-file-using-javascript/ Share on other sites More sharing options...
litebearer Posted January 13, 2011 Share Posted January 13, 2011 Perhaps the javascript forum might know Quote Link to comment https://forums.phpfreaks.com/topic/224305-open-a-text-file-using-javascript/#findComment-1158884 Share on other sites More sharing options...
brianlange Posted January 13, 2011 Share Posted January 13, 2011 I put the code on my server and it works fine. If I update the text file the changes are displayed. http://gonavygolf.com/test15.php Quote Link to comment https://forums.phpfreaks.com/topic/224305-open-a-text-file-using-javascript/#findComment-1159012 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.