?
Solved

Javascript XML counter

Posted on 2010-08-23
15
Medium Priority
?
678 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:Gurvinder Pal Singh
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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
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…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

649 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