Solved

Javascript XML counter

Posted on 2010-08-23
15
669 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
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 …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

13 Experts available now in Live!

Get 1:1 Help Now