jclarke
04-20-2006, 03:04 AM
I need to know if it's possible to store an external text file into a variable to use later?
|
Click to See Complete Forum and Search --> : Importing an external text file jclarke 04-20-2006, 03:04 AM I need to know if it's possible to store an external text file into a variable to use later? mrhoo 04-20-2006, 03:11 AM The easiest way is to use an XMLHttpRequest to get the file and store the reponseText in your global variable jclarke 04-20-2006, 05:02 AM The easiest way is to use an XMLHttpRequest to get the file and store the reponseText in your global variable Could anyone show me how to do that? TheBearMay 04-20-2006, 06:51 AM Here's one way: var fileContent = getFile("pathToFile"); function getFile(fileName){ oxmlhttp = null; try{ oxmlhttp = new XMLHttpRequest(); oxmlhttp.overrideMimeType("text/xml"); } catch(e){ try{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ return null; } } if(!oxmlhttp) return null; try{ oxmlhttp.open("GET",fileName,false); oxmlhttp.send(null); } catch(e){ return null; } return oxmlhttp.responseText; } jclarke 04-20-2006, 09:52 PM thanks!! webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |