trickstar34 Posted June 30, 2009 Share Posted June 30, 2009 (edited) OK, I am trying to make a hit counter for my web page but I can't, I keep getting a compilation error. Here is my code that is the problem, but the thing is I don't know why it's wrong. <script language="JScript" runat="server">var counterDoc : XmlDocument = Server.MapPath("design/server/hits/home.xml");var counterTag : XmlElement = counterDoc.getElementById("hits");var hits : Int = counterTag.value.ToInteger;var counter : Int = hits + 1;counterDoc.file.RemoveChild("counter");counterDoc.file.CreateElement("counter");counterDoc.file.counter.SetAttribute("id", "hits");counterDoc.file.counter.AppendChild(counterDoc.CreateTextNode(counter));counterDoc.Save("design/server/hits/home.xml");</script> And my XML document <?xml version = "1.0"?><file><counter id="hits">0</counter></file> I just can't see whats wrong, can someone help me get to the bottom of this or show me an easier way of doing this? If you want to see what the error is go to this link. Edited June 30, 2009 by trickstar34 Link to comment Share on other sites More sharing options...
PatrickW Posted June 30, 2009 Share Posted June 30, 2009 I don't think "file" is a valid member of the XmlDocument object, I guess you have to access the file section of your XML file with "getElementsByTagName ('FILE')". But why are you removing and recreating the counter element ? Can't you just do: <script language="JScript" runat="server">var counterDoc : XmlDocument = Server.MapPath("design/server/hits/home.xml");var counterTag : XmlElement = counterDoc.getElementById("hits");var hits : Int = counterTag.value.ToInteger;counterTag.value = hits + 1;counterDoc.Save("design/server/hits/home.xml");</script> Link to comment Share on other sites More sharing options...
trickstar34 Posted June 30, 2009 Author Share Posted June 30, 2009 I've tried that before, I don't know why that doesn't work either, so I thought that might work. Go check that link, I changed it and now it's saying there is something wrong with that, I'm running on the Windows server, not Linex, if that helps Link to comment Share on other sites More sharing options...
fred Posted June 30, 2009 Share Posted June 30, 2009 Shouldn't .ToInteger be .ToInteger()? Admittedly I don't know anything about .net but the way you have it, I'd expect hits to contain the function instead of an integer, which would then cause problems when you try to add 1 to it. Link to comment Share on other sites More sharing options...
trickstar34 Posted June 30, 2009 Author Share Posted June 30, 2009 ToInteger() is unproper ASP.Net, it's not exactly a function, it just tells the compiler to understand it as an integer, just as .ToString tells it to understand it as a string. As you see when you click the link, it will say the following line is the problem. counterTag.value = hits + 1; It seems to me that everytime I minipulate a file it will give out an error, so I just don't see whats wrong, thats why I am asking if anybody has an easier way of making a hit counter. Link to comment Share on other sites More sharing options...
PatrickW Posted June 30, 2009 Share Posted June 30, 2009 (edited) If you click on the link "Show Detailed Compiler Output:" on that error-output, you see at the bottom a list with warnings and errors. It looks like the problems start a bit before the indicated line. I'm not an ASP.net expert sadly Edited June 30, 2009 by PatrickW Link to comment Share on other sites More sharing options...
trickstar34 Posted June 30, 2009 Author Share Posted June 30, 2009 Do you have any other ideas? Link to comment Share on other sites More sharing options...
PatrickW Posted June 30, 2009 Share Posted June 30, 2009 Don't the surrounding <javascript> tags mean that you should use proper javascript syntax for this piece of code ? Link to comment Share on other sites More sharing options...
trickstar34 Posted June 30, 2009 Author Share Posted June 30, 2009 (edited) No, for some reason you have to use that type of syntax although you can use JScript functions and coding style, the tag just tells the server which compiler to use. But it does mostly follow JScript syntax, it is just that segment of code because I have other ASP scripts running and they worked just fine before I attempted to add the counter. Does anyone have any other ideas for making a hit counter with ASP.Net with JScript? Edited June 30, 2009 by trickstar34 Link to comment Share on other sites More sharing options...
PatrickW Posted July 1, 2009 Share Posted July 1, 2009 You can have a look here, for a Jscript hitcounter for asp.net: http://webscripts.softpedia.com/scriptDown...load-40035.html From what I read on the web, you should use proper Jscript syntax, if you use the <script language="JScript" > tag. You cannot use the VBscript syntax inside those tags. I guess that's what all the warnings and error messages on the error-report complain about. Link to comment Share on other sites More sharing options...
trickstar34 Posted July 1, 2009 Author Share Posted July 1, 2009 (edited) How was I using VB? That's how I was taught to do it. When I use things that work with regular JScript (client-side), they dont work. I get compilation issues whenever I use JScript syntax if else's That tutorial doesn't work either because I use ASP.Net which uses almost completely different syntax. And it is also only counting people from specific IP's, not showing how many times people have viewed it total. Edited July 1, 2009 by trickstar34 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now