21,886
社区成员
发帖
与我相关
我的任务
分享
var localurl = document.location;//先获取当前链接
function urls(v)
{
var xmlHttp;
xmlHttp=new XMLHttpRequest();
//跳转处理页面
xmlHttp.open("GET",v,true);
xmlHttp.send(null);
}
//获取展示次数
window.onload =function(){
var url="http://localhost/test.php?url="+encodeURIComponent(localurl);
urls(url);
}
////广告点击统计
function cc(){
var url="http://localhost/test.php?curl="+encodeURIComponent(localurl);
urls(url);
}
<html>
<head></head>
<body>
<a href="http://www.google.com/" vdata="go" onclick="cc()">This is ads1</a><br/>
<a href="http://www.bing.com" vdata="go" onclick="cc()">This is ads2</a><br/>
<a href="http://www.baidu.com" vdata="go" onclick="cc()">This is ads3</a>
</body>
<script src="jquery-1.5.1.min.js"></script>
<script src="url.js"></script>
</html>
function cc(){
localurl = document.location;
$.get('http://localhost/test.php', {curl:$(location).attr('href')});
}
或$(function() {
$('[vdata="go"]').click(function() {
$.get('http://localhost/test.php', {curl:$(location).attr('href')}, function(d){ alert(d)});
});
});
<a href="http://www.google.com/" vdata="go">This is ads1</a><br/>
<a href="http://www.bing.com" vdata="go">This is ads2</a><br/>
<a href="http://www.baidu.com" vdata="go">This is ads3</a>
3、至于你的代码中的问题,多半是
xmlHttp=new XMLHttpRequest();
引起的。不是每个浏览器都有 XMLHttpRequest 的