Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:23:50+00:00 2026-06-03T20:23:50+00:00

Hi everyone i write code for tracking user click on links and record them

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:23:53+00:00Added an answer on June 3, 2026 at 8:23 pm

    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:

    $('a').click(function(e) {
        e.preventDefault();
        var url = $(this).attr('href');
        $.post("get.php", { name: "John" }, function() {
            location.href = url;
        });
    });
    

    However, middle-clicking a link will not trigger this event. If you always want to fire your event, use a mousedown event and check e.which. If it’s 1 it was the left button and you need to e.preventDefault() and redirect after the AJAX request finished. If it’s 2 it 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.

    $('a').on('click mousedown', function(e) {
        if(e.which == '3') {
            return; /* do not handle rightclick */
        }
        else if(e.type == 'click' || e.which == '1') {
            e.preventDefault();
        }
        var url = $(this).attr('href');
        $.post("get.php", { name: "John" }, function() {
            if(e.type == 'click' || e.which == '1') {
                location.href = url;
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone i am trying to write this code and I am having problems
Everyone know about Google Analytics tracking code. It's a javascript code similar to one
everyone! It's nice to work with Ruby and write some code. But in past
Hello everyone I am trying to write a string on image during runtime and
Everyone, every blog is talking about HTML 5 and giving solution to use HTML
I need to write some code that deals with generating and manipulating multivariable polynomials.
Morning Everyone, I've been attempting to write an application that does some GETs from
I frequently write C# code that has to use magic strings to express property
Even experienced programmers write C# code like this sometimes: double x = 2.5; double
What's up y'all, I am trying to write some code in Java that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.