![](/img/trans.png)
[英]I have successfully loaded a form into a <div> element using jQuery $.Ajax. I need to know how to submit that form using jQuery Ajax
[英]Tracking Clicks using jQuery and Ajax. I dont have access to any html/other files
我有食谱名称缩略图的列表,我想跟踪人们单击的食谱。 我的问题是,我可以使用jQuery严格执行此操作,而没有其他操作。 我无权访问该网站的任何其他页面。
到目前为止,我所做的是我检查了配方和图像的名称,并在jquery中使用.addClass()添加了一个通用类,此后不久,我对该名称声明了onclick函数。
然后,例如,获取标签的磁贴(这是食谱名称),然后将其存储在数据库中的其他网站的信息发送出去。
问题是我的点击次数并非一直都有。 到现在为止,这种行为对我来说还是随机的,我不知道某些点击是如何存储的,而有些点击则没有!! 我对网络进行了研究,发现的唯一相关内容就是将缓存保留为假。 我也尝试过,但是行为保持不变。 点击仅在某个时间存储。
我现在正在本地主机上执行此操作,我需要将此信息存储在我的其他网站上。
jQuery(window).load(function(){
jQuery('.del-space .thumbnail a').addClass("recipeLinks");
$(".recipeLinks" ).on("click",function(event) {
var user=jQuery('loggedinuser').attr('title');
//alert(user);
if(typeof(user)==="undefined"){
user='Guest';
}
var recipeName=$(this).attr('title');
var data='recipeName='+recipeName+'&user='+user;
$.ajax({
url: "http://myotherwebsite.com/tracking/storeClick.php",
cache: false,
type: 'POST',
data: data,
beforeSend: function() {
},
success: function(data, textStatus, xhr) {
//alert('done');
//window.location = location.href;
},
error: function(xhr, textStatus, errorThrown) {
//alert("error");
}
});
});
除此之外,我还想知道,当我将这段代码实时发布时,一次会有很多点击,我能否记录所有点击?
使用event.preventDefault()
来阻止单击立即更改页面,以便您的Ajax请求有时间完成,并在Ajax完成后使用window.location
来更改页面
jQuery(window).load(function(){
jQuery('.del-space .thumbnail a').addClass("recipeLinks");
$(".recipeLinks" ).on("click",function(event) {
event.preventDefault(); //stop the default action
//the action will take place after
//ajax is complete
var href = jQuery(this).attr("href"); //get the location to goto
var user=jQuery('loggedinuser').attr('title');
//alert(user);
if(typeof(user)==="undefined"){
user='Guest';
}
var recipeName=$(this).attr('title');
var data='recipeName='+recipeName+'&user='+user;
$.ajax({
url: "http://myotherwebsite.com/tracking/storeClick.php",
cache: false,
type: 'POST',
data: data,
beforeSend: function() {
},
success: function(data, textStatus, xhr) {
//alert('done');
window.location = href; //now goto the links href
},
error: function(xhr, textStatus, errorThrown) {
//alert("error");
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.