?
Solved

Javascript XML counter

Posted on 2010-08-23
15
Medium Priority
?
677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 1000 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 111

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 111

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
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 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.
Suggested Courses

743 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