Firefox中的Ajax问题

I'm counting clicks on a link by calling a page with AJAX but in Firefox, apparently because the page called is never actually loaded, for some reason Firefox never calls it. It seems like the link is clicked and then Firefox makes the AJAX call but somehow because the page changes to the actual link in the href then the AJAX call is never actually sent (appears red in firebug and no sign of it in Fiddler). It works fine in IE & Chrome and if I change the link to target="_new" then it will work in Firefox. Am I making some sort of stupid mistake?

<HTML>
<HEAD>
<script type="text/javascript">
function adtrk(cde){
var ajaxRequest;  // The variable that makes Ajax possible!
    var r=Math.random();
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaresp = ajaxRequest.responseText;
        }
    }

    ajaxRequest.open("GET", "/atr.php?cde=" + cde + "&r=" + r, true);
    ajaxRequest.send(null);
}

</script>
</HEAD>
<BODY>
<a onclick="adtrk('zip1'); return true;" href="http://www.google.com"><img src="/images/img.jpg"></a>
</BODY>
</HTML>

When you load a new page any open AJAX requests will be cancelled (by the browser). Your server probably never sees the click count request.

Either always open links in a new window or use some other mechanism for counting clicks, like a proxy/redirect.

The page changes before the ajax request is done. You should wait for you ajax request to end before changing page by running it synchronously :

ajaxRequest.open("GET", "/atr.php?cde=" + cde + "&r=" + r, false);