ajax问题

pingheguo 2010-10-22 12:35:14
js代码如下
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}

function add(url){
S_xmlhttprequest();
xmlHttp.open("GET","add.php?id="+url,true);
xmlHttp.onreadystatechange=byphp();
xmlHttp.send(null);
}

function byphp(){
var byphp100=xmlHttp.responseText;
document.getElementById('aa').innerHTML=byphp100;
}

add.php代码如下


<?php
if($id=$_GET[id]){
for($i=1;$i<20;$i++){
echo $id;
}
exit();
}
?>

index.php页如下

<script src="ajax.js" type="text/javascript"></script>
<a class="yellow_link" href="" onclick="add('1')">选择优惠券</a>
<div id="aa"></div>


没效果为什么 帮我看下 大家 谢谢
...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
function add(url){
S_xmlhttprequest();
xmlHttp.open("GET","add.php?id="+url+'&_dc='+new Date().getTime(),true);//防IE缓冲
xmlHttp.onreadystatechange=byphp//================();
xmlHttp.send(null);
}

function byphp(){
if(xmlHttp.readyState==4){//要在状态为4时才能使用xhr对象的responseText属性,要不出错
var byphp100=xmlHttp.responseText;
document.getElementById('aa').innerHTML=byphp100;
}
}


<?php
if($id=$_GET["id"]){//=========你这句判断有问题吧,没见你给$id赋值,$_GET也没用对吧。。
for($i=1;$i<20;$i++){
echo $id;
}
exit();
}
?>

junge2 2010-10-22
  • 打赏
  • 举报
回复
把xmlHttp.onreadystatechange=byphp();的()去掉。

52,780

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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