Solved

Javascript XML counter

Posted on 2010-08-23
15
673 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
ID: 33509191
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
ID: 33510739
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
ID: 33511359
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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 250 total points
ID: 33511393
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33511395
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
ID: 33511534
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33511638
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
ID: 33511924
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 110

Expert Comment

by:Ray Paseur
ID: 33611499
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
ID: 33639837

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 110

Expert Comment

by:Ray Paseur
ID: 33640281
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
ID: 33823527
Thanks!!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33823652
You're welcome! Thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

685 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