Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Hi question about storing contents of a file

Hi question about storing contents of a file

lateralus
11-23-2005, 11:19 AM
Hi, i'm quite new in javascript....
I found a script which reads tha contents of a file stored on the web server and prints it on screen like an include.. i want to modify this script so the contents of the file stored on a javascript variable. the script is the following:

<SCRIPT LANGUAGE="JavaScript">

// new prototype defintion
document.include = function (url) {
if ('undefined' == typeof(url)) return false;
var p,rnd;
if (document.all){
// For IE, create an ActiveX Object instance
p = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
// For mozilla, create an instance of XMLHttpRequest.
p = new XMLHttpRequest();
}
// Prevent browsers from caching the included page
// by appending a random number
rnd = Math.random().toString().substring(2);
url = url.indexOf('?')>-1 ? url+'&rnd='+rnd : url+'?rnd='+rnd;
// Open the url and write out the response
p.open("GET",url,false);
p.send(null);
document.write( p.responseText );
}
</SCRIPT>

and for printing the contets of the file i must write inside the body of my
<script>
document.include('header.inc');
</script>

i just want to strore the contents on a variable and not print them

thanks a lot for your time

Bonker
11-23-2005, 11:28 AM
var yourString = p.responseText;

lateralus
11-23-2005, 11:57 AM
thanks for your help... now i would like to ask

i use var myvar = p.responce.Text inside the function

so i call then the function: document.include('myfile');

i've tried inside another function to store the result like
var result = document.include('myfile');
is it possible?...because nothing is being stored
thnaks once more for your time

Bonker
11-23-2005, 01:23 PM
Then you should use: return p.responseText; inside the include function, otherwise your function doesn't return anything.

Be aware that your variable will only contain a value when the request is finished. It's safer to use asynchronous XmlHttp together with an event see for example http://www.15seconds.com/issue/020606.htm


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Temperature Converter Problem
Open Excel file w/Javascript - can't get link to work (but input btn works)
How can I change the Font color in a menu for multiple pages?
Script behaves differently - Same IE/OS
Unable to capture data from verified fields on a form
javamenu and screen size?
using onClick event with a button and textbox...

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics