Hi everyone i write code for tracking user click on links and record them on php pages. Thi is my code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Tracking outgoing links with JavaScript and PHP</title>
</head>
<body>
<p><a href="test2.html">Test link to Google</a></p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(function() {
$('a').click(function() {
$.post("get.php", { name: "John" }
});
});
</script>
</body>
</html>
It is working, the page get.php is requseted but not completed. So the data cannot be saved. it seems page move too quick
How to solve this problems. Thanks so much
Navigating away might abort the AJAX request before it was fully sent. To avoid this, do not load the target page before the request has finished:
However, middle-clicking a link will not trigger this event. If you always want to fire your event, use a
mousedownevent and checke.which. If it’s1it was the left button and you need toe.preventDefault()and redirect after the AJAX request finished. If it’s2it was the middle button and you only need to send the AJAX request and not do anything else – the page will open in a new tab anyway.