HTML, Ajax, JavaScript... question

Hi there…
just a small question - does someone here know if it is doable (and if so - how?) to make Download Counter without PHP/ASP/MySQL just with HTML, Javascript (maybe Ajax?) and flat files?

HTML, AJAX/Javascript are all client side. You need something server side to do the counting. You don’t need mysql, you but you’ll need php, asp, or cgi to store the download count somewhere.

I think the closet you’ll get is a javascript cookie but that’ll only write to a client side file.

A flat file hosted on the server will need a server side language to read and write, like php.

Ajax uses php or asp for server side functions as well, so I don’t think there’s an Ajax solution either.


As above

In order to accurately track actual downloads you will have to implement something very simple on the server - some script that just reads a value in a file and increments it. Later display that value by using SSI (server side includes) in your html or use AJAX to load it and place it somewhere on the page.
The setup will be something like that:
in the html have a link to the download

<a href="" id="myDownloadLink">Download</a>

<p>This file has been downloaded so many times: <span id="myDownloadLinkCounter"></span></p>

//this is jQuery code that will perform an ajax request to the server
$( function() {

$.ajax( {
   type: "GET",
   url: "theydownloadmyfile.php",
   data: "",
   success: function(msg){
      $( '#myDownloadLinkCounter' ).text( msg );
} );

$( '#myDownloadLink' ).click( function()
$.ajax( {
type: "POST",
   url: "theydownloadmyfile.php",
   data: "",
   success: function(msg){
} );
return true;
} )
} );

If it is possible to implement any server side script this will work. I can provide the php for that. If not, than it’s irrelevant, but you still can use some of the jQuery code.

i already thouht it would end up with something like that… damn limitation about the used languages… If i was able to use PHP it would be done in seconds, but the host i have to use does neither have any server side scripts nor a database ><
I just thought that javascript was somehow able to do some serverside stuff (like editing a file) as well…
Thanks for your help anyway.

You can use some code similar to what I proposed to “hit” some image counter service. And then display the image in the page.

hm… i just begin to think about using my personal server for tracking the hits with your code… that could be…interestering.

If you have a server at hand and you know php then everything is simpler. Use JSONP ajax requests with jQuery (read here Basically behind the scenes jQuery creates a script tag with an url on a remote server. When the data is loaded a callback function is invoked. Pretty simple to use.