使用 jQuery 跟踪链接点击的问题
我有以下代码:
<a href="http://mydomain.com/link123" class="someClickEvent">Some Link</a>
$(document).ready(function(){
$('.someClickEvent').click(function() {
var $deal_id = 0;
var $position = 0;
var data = {
deal_id : $deal_id,
position : $position
};
$.ajax({
type : 'POST',
data: data,
url : '/ajax/trackBannerClick',
success : function(data){
return true;
}
});
});
});
而且,在用户发送到新 URL 之前,单击事件似乎尚未完成。有没有办法确保点击事件在将用户发送到新 URL 之前已完成?我不想使用 window.location 因为它对 SEO 不友好。
I have the following code:
<a href="http://mydomain.com/link123" class="someClickEvent">Some Link</a>
$(document).ready(function(){
$('.someClickEvent').click(function() {
var $deal_id = 0;
var $position = 0;
var data = {
deal_id : $deal_id,
position : $position
};
$.ajax({
type : 'POST',
data: data,
url : '/ajax/trackBannerClick',
success : function(data){
return true;
}
});
});
});
And, it seems that the click event doesn't finish completing before the user is sent to the new URL. Is there a way to make sure the click event has finished prior to sending the user to the new URL? I'd rather not use window.location since it isn't SEO friendly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为添加
async: false
可能会导致脚本在调用success
函数之前等待Ajax完成:参考:
$.ajax()
。I think that adding
async: false
might cause the script to wait for the Ajax to complete before calling thesuccess
function:Reference:
$.ajax()
.