Reputation: 345
I'm trying to do something simple, capture any click event and send the url to a php script.
With the alert(a);
the ajax.php
will be call every single time, if I remove it, once every 20 clicks will work, I wonder if it's because the alert(a)
slow things down ?
$('a').click(function(){
var a = $(this).attr('href');
$.ajax({
type: "POST",
url: "/ajax.php",
data: { b1: a , b2: "456" },
});
alert(a);
});
Upvotes: 0
Views: 262
Reputation: 49919
If you click on the A, there is still the event to go to another page. So do this:
$('a').click(function(e){
e.preventDefault();
var a = $(this).attr('href');
$.ajax({
type: "POST",
url: "/ajax.php",
data: { b1: a , b2: "456" },
success : function(){
document.location = a;
}
});
});
Upvotes: 1