The Sea King Posted November 11, 2007 Share Posted November 11, 2007 How do make a javascript code that loads a text file? Link to comment Share on other sites More sharing options...
Synook Posted November 11, 2007 Share Posted November 11, 2007 Use AJAX <script type="text/javascript"> //Function returns the contents of the file specified in the parameter function getText(file) { //Create the xmlHttpRequest object xmlHttp = new XMLHttpRequest(); if (!xmlHttp) xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //This procedure runs after state changes in the connection xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState == 4) { //If the file has fully loaded return xmlHttp.responseText; } } //Establish a connection to your file xmlHttp.open("GET", file, true); //Send (nothing) this just makes the server respond xmlHttp.send(null); }</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.