Q:

Download counter

Here's one to think about...
I've created a jQuery & PHP procedure that allows me to count the amount of times a file has been downloaded.
update!
the new jQuery code after reading your answers:
$(document).on('click', 'a.download', function() {
    var id = $(this).attr('id');
    var act = 'downloaded';

    request = $.ajax({
        url: "view/jquery/player.doitem.php",
        type: "post",
        data: { id : id, act : act },
        dataType: "json"
    });
    request.done(function(data) {
        window.location(data.download);
    });
});

the new PHP code:
$id = intval($_POST['id']);
$act = $_POST['act'];

$sql = "update media set " . $act . "=" . $act . "+1 where id='" . $id . "' limit 1";
$main->query($sql);

$sql = "select * from media where id='" . $id . "' limit 1";
$result = $main->query($sql);
$row = mysqli_fetch_array($result);
$title = $row['title'];
$srctype = $row['source_type'];
$filename = $row['filename'];
$srcuri = $main->getSrcUri($srctype, $filename);
$download = $main->getSiteConfig("media_ext_src") . "/" . $main->getSiteConfig("media_ext_dir") . "/download.php?file=" . $filename;

$data = array("srcuri" => $srcuri, "title" => $title, "download" => $download);
$data = json_encode($data);

echo $data;

The download counter works properly, every time the download link is clicked the PHP script is fired and the database is updated.
But it doesn't start the actual download. I thought using window.location() would trigger the browser to start the download, but it doesn't.
How can I tell jQuery to download the file using the data returned from the PHP script?

A:

If everything in life was just as easy as coding...
Figured out that using an invisible <iframe> as proposed in another stackoverflow thread solves the download problem as stated above.
The database is updated, the download initiated by the browser and I'm a happy little coder again :)
Thanks all for your input!

