php js ajax get 没反应,求助.

chenxinjian007 2014-01-01 08:19:01
url.js 代码
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页面代码
<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>


为什么cc()这个方法在test.php中没执行呢.郁闷了
...全文
200 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenxinjian007 2014-01-04
  • 打赏
  • 举报
回复
我那个代码测试了是没问题的. 主要问题是我粗心把数据库中的表更新错了. 唉.我太大意了,谢谢大家的回复.结贴
xuzuning 2014-01-02
  • 打赏
  • 举报
回复
1、js文件放在哪里都无关紧要,当然最好是放在 head 标签内 2、既然你已经加载了 jquery,那么就应该使用 jquery 提供的 ajax 功能,而不是自己再写一套
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 的
码无边 2014-01-02
  • 打赏
  • 举报
回复
cc()未执行,你是因为url.js都没调用,将jquery类库和url.js 放在head里面,这样调用cc(),才会生效。
xuyanlu 2014-01-01
  • 打赏
  • 举报
回复
用firebug查看下是否错误提示信息...
一起混吧 2014-01-01
  • 打赏
  • 举报
回复
将 <script src="jquery-1.5.1.min.js"></script> <script src="url.js"></script> 放在head里面

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧