ThemeForest

Ajax click track when opening in same tab

221 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • India
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
atinder says
hey guys have a quick question i am tracking link clicks with ajax. i have some html code like this
<a href="googl.com" class="my-link"></a>link
and some jquery code like this
$('a.my-link').live('click', function() {
$.ajax({----------});
});

is there any change that link will open before the ajax callback is made ? thanks

165 posts
  • Has been a member for 0-1 years
  • Europe
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
  • Bought between 1 and 9 items
SakuraPixel says

hey guys have a quick question i am tracking link clicks with ajax. i have some html code like this
<a href="googl.com" class="my-link"></a>link
and some jquery code like this
$('a.my-link').live('click', function() {
$.ajax({----------});
});
is there any change that link will open before the ajax callback is made ? thanks
If you ask me “Yes there is!”, I guess you should make sure that the ajax request was completed, than proceed opening the page. Ex:
function click(e){
e.preventDefault();
currentLink = jQuery(this).attr('href');
ajax.call(callback)
}

function callback(){
//could be error
//could be success
//now open the URL(currentLink)
}

Anyway I think this would be bad practice (for all links) – pretty heavy for the server, no to mention that user would wait a couple of seconds before you get the ajax response.

jayc

221 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • India
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
atinder says

thanks SakuraPixel exactly no one likes to wait just to open a link. so its not a practical idea. as i can see in my plugin right now ajax click tracking works fine without adding any complexity.

by
by
by
by
by