can someone write me simple js

Any problem with javascript can be discussed here.
Locked
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

can someone write me simple js

Post by Lixas »

I need that script read external file in write its content to variable. Maybe someone will be able to help me. I have tried do it by myself, but i have failed :(


Image
medwebinc
Posts: 87
Joined: Wed Mar 02, 2005 4:26 pm

Post by medwebinc »

I dont believe there is a way to write that in javascript (If I am wrong please correct me) but there are other ways for example with activeX or Java applets.
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

ok, so if i'm not able to read external file in the same server so i will use php for reading and "echo" to javascript variable :D
PHP RULEZZ
Image
kaos_frack
Posts: 504
Joined: Sat May 07, 2005 8:03 am
Contact:

Post by kaos_frack »

just enter src attribute in your script tag
like this:
<script type="text/css" language="javascript" src="./myScript.js"></script>
leegao
Posts: 15
Joined: Thu Aug 10, 2006 3:46 am
Contact:

Post by leegao »

hey, there is a way to read a file on the server using the xmlHttpRequest object, its usage is this

Code: Select all

var xhr
if (ActiveXObject("Msxml2.XMLHTTP"))
{
xhr = new ActiveXObject("Msxml2.XMLHTTP")
}
else if (ActiveXObject("Microsoft.XMLHTTP"))
{
xhr = new ActiveXObject("Microsoft.XMLHTTP"))
}
else {
xhr = new XMLHttpRequest()
}

 xhr.open("GET", "filename.txt",true); 
 xhr.onreadystatechange=function() {
  if (xhr.readyState==4) {
   ****.getElementById("divChange").firstChild.value = (xhr.responseText)
  }
 }
 xhr.send(null)
Locked