...

View Full Version : Reading file content



Vladdy
12-20-2003, 05:13 PM
The questions "Can I read a file... " show up on the regular basis. The answer to accessing files on the same domain is the XMLHTTP object. Following is a simple wrapper that accounts for differences in Gecko and IE5.5+ implementation and returns the content of a file in a string, or null if an error occured:


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;
}

swmr
12-20-2003, 09:06 PM
useful information... thanks :)

pcweirdo
01-12-2004, 06:26 AM
which browsers have this object? is it just windows?

liorean
01-12-2004, 09:48 AM
Hmm, seems a lot like my importing file as string (http://codingforums.com/showthread.php?s=&threadid=14463) script, some time back.

Vladdy
01-12-2004, 03:07 PM
Did not know you posted a similar script, liorean.

LeXRus
01-13-2004, 05:51 AM
this function doesnot work in my mozilla 1.6a. y?
could you tell me when can i get the reference of the object "XMLHttpRequest" in mozilla version

and as i know MSXML2.XMLHTTP is not available at IE 5.0 if some one has not installed MSXML2 parser or MDAC(which updates the MSXML) yet.

here is a version list of msxml:
http://www.perfectxml.com/msxmlRef.asp

and i prefer startDownload method
of ie default behaviors
http://msdn.microsoft.com/workshop/author/behaviors/reference/methods/startdownload.asp?frame=true

liorean
01-13-2004, 08:12 AM
Been supported since before 1.0 version, IIRC.
<http://unstable.elemental.com/mozilla/build/latest/mozilla/extensions/dox/classnsXMLHttpRequest.html>,
<http://unstable.elemental.com/mozilla/build/latest/mozilla/extensions/dox/classnsXMLHttpRequest-members.html>,
<http://www.mozilla.org/newlayout/xml/>,
<http://www.mozilla.org/xmlextras/>

My version uses an older MSXML than this, maybe that works in ie5.0w.

looka
01-10-2005, 08:27 AM
hay, i'm using this script for importing different pieces of html in my page. but, in IE only, sometimes (i dont know under what circumstances) when i import a FORM the script crashes entire explorer (including taskbar and background of windows). any ideas what could do that?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum