u just wanted to implement a very basic download counter.
when clicking on the link an ajax request should be sent to the server and after this the download should start.
<a href="<?= $update->link ?>" onClick="downloadCount(<?= $update->id ?>);"><?php echo img(array("height" => "24", "src" => "images/btn_free.png")); ?></a>
That’s how i generate the link.
function downloadCount(id_) {
$.ajax({
url: '<?= base_url() ?>index.php/updates/incCount/' + id_.toString(),
success: function() { return true },
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
url is correct (if i copy the url everything is ok)
but when clicking the link i just got the 2 alerts (1st with 0 and 2nd is empty)
when i add return false; in the onClick part the link isn executed and the ajax call is successfull
when i add return false; to my function the link proceeds everytime (WHY??) and the ajax call returns in an error.
The domain is the same so this should not be the reason…
I’m kinda confused due this normally very easy task >_<
Clicking the link causes the browser to navigate to another page, this aborts any outstanding ajax requests – which is why you’re getting an error.
If you wish for your
downloadCountfunction to determine whether the page should reload or not, you need to return this value from your handler: