Pages: [1]   Go Down
Author Topic: HTML, Ajax, JavaScript... question  (Read 987 times)
0 Members and 1 Guest are viewing this topic.
Bonn, Germany
Offline Offline
God Member
*****
Karma: 0
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 01, 2009, 08:18:45 am by cmiyc » Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
God Member
*****
Karma: 0
Posts: 731
skcor oniudrA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  

Edit:

As above
« Last Edit: June 01, 2009, 08:21:17 am by John_Ryan » Logged

Sofia, Bulgaria
Offline Offline
Full Member
***
Karma: 0
Posts: 237
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:

<a href="http://server.com/file.zip" id="myDownloadLink">Download file.zip</a>

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

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



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


$( '#myDownloadLink' ).click( function()
{
$.ajax( {
type: "POST",
   url: "theydownloadmyfile.php",
   data: "filename=file.zip",
   success: function(msg){
   }
} );
return true;
} )
} );
</script>

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.
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 0
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
so..
Thanks for your help anyway.
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Sofia, Bulgaria
Offline Offline
Full Member
***
Karma: 0
Posts: 237
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Bonn, Germany
Offline Offline
God Member
*****
Karma: 0
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Sofia, Bulgaria
Offline Offline
Full Member
***
Karma: 0
Posts: 237
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have a server at hand and you know php then everything is simpler. Use JSONP ajax requests with jQuery (read here http://api.jquery.com). 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.
Logged

Pages: [1]   Go Up
Jump to: