Solved

Javascript XML counter

Posted on 2010-08-23
15
668 Views
Last Modified: 2013-11-19
I would like to know how to use javascript to read and write to a text file.  I currently have a javascript code that reads from a text file, but now I want to update the text file.  How do I do that?

Here is the code below:

<SCRIPT language = "Javascript">

objXml = new ActiveXObject("Microsoft.XMLHTTP");

// objXml = new ActiveXObject("Msxml2.XMLHTTP"); older version
var datafile = "data.txt";

objXml.open("GET", datafile, true);
objXml.onreadystatechange=function() {
   if (objXml.readyState==4) {
       display(objXml.responseText);
  }
 }

objXml.send(null);

function display(msg) {
  document.write(msg);
}

</SCRIPT>

O'Neil
0
Comment
Question by:superoneio
  • 5
  • 4
  • 2
  • +1
15 Comments
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
I dont think if you can create a physical file using javascript.
You can create the xml string and send it to server, where server side script will generate the physical file for you
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
Comment Utility
You need to use ActiveX so the script will work only on IE browsers :

Check Example 5 here : http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm
0
 

Author Comment

by:superoneio
Comment Utility
How do I update an XML or text file from Javascript?

I need an Intranet counter that uses no server side scripting:ASP, PHP, etc.  I need it to be in XML or Javascript, Flash or any technology that runs in a basic HTML webpage.
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 250 total points
Comment Utility
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
Where's the XML to write/modify ? @gurvinder372 give you an answer for the server side, there's no way to modify a file on a server without server side scripting/program.
I give you the answer for a local file.
0
 

Author Comment

by:superoneio
Comment Utility
Leak, the answer you gave worked on my computer, but when I moved it to the server it don't work, maybe because the browser is blocking the Write() I dunno.  I just tried Java Applets and it the Share Point Server is blocking the .Class files from being uploaded.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 82

Expert Comment

by:leakim971
Comment Utility
yes of course, generaly server block activex
I don't know your final needs but you may use native vbscript or powershell(2008+) on the server to modify the xml file directly without using a browser.
0
 

Author Comment

by:superoneio
Comment Utility
Gurvinder, I think yours can work, but nothing is showing.  I am using IE6.

Thanks alot guys for helping me figure this one out.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
IE6??  Aren't you a little concerned about its age?

Maybe if you describe what you are trying to do in non-technical terms we can help.  I cannot get my head around why anyone would want to write a file to a server but would not want to use a server-side scripting language.  It's not a design pattern that makes any sense.  So if we know what you're trying to do, maybe we can propose something sensible for you.
0
 

Author Comment

by:superoneio
Comment Utility

I have sharepoint and I have an Intranet site in a sharepoint folder.  We need a hit counter that is not blocked to operate in sharepoint.  For example, ASP, .class codes and EXE codes are blocked from being uploaded.  So, we're stuck with javascript, XML, and HTML to name a few.  It is intranet, not internet, so I wouldn't worry about security that much.  But what do you suggest?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
OK, thanks for posting that; did not know it was Sharepoint, and I am not at all an expert there.  See if this search has anything useful for you.  The titles sound promising, but I would not be able to evaluate the quality of the content.
http://lmgtfy.com?q=sharepoint+hit+counter

;-)

Best of luck with it, ~Ray
0
 

Author Closing Comment

by:superoneio
Comment Utility
Thanks!!
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
You're welcome! Thanks for the points!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now