部分代码:foreach($titlere as $valre){ ?>
<tr>
<td width="50%" scope="col"> <a href="javascript:void(0)" onclick="record2('<?=$valre[id]?>')"><?=$valre[swap_title]?></a></td>
</tr>
<?php } ?>
同页面内获取鼠标点击后的<?=$valre[id]?>的值,(目的是做再次的查询并输出结果)。
<tr>
<td width="50%" scope="col"> <a href="javascript:void(0)" onclick="record2('<?=$valre[id]?>')"><?=$valre[swap_title]?></a></td>
</tr>
<?php } ?>
同页面内获取鼠标点击后的<?=$valre[id]?>的值,(目的是做再次的查询并输出结果)。
createXMLHttpRequest();
method = "GET";
//alert('swap_id-->>'+swap_id);
url = "action.php?swap_id="+swap_id+"&ran="+Math.random();
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = show3;
xmlHttp.send();
}
当前页是index.php,record2该怎么写呢?麻烦帮忙写下
function record2(param){
//将当前参数赋给全局变量abc,那么在此函数内外都可调用
abc = param;
//或者在当前函数跳转时加参数,那么后端用GET接收
location.href="xxx.php?an="+param;
}#第二种情况的GET接收页面
if(isset($_GET['an'])){
print_r($_GET['an']);
}
createXMLHttpRequest();
method = "GET";
//alert('swap_id-->>'+swap_id);
url = "action.php?swap_id="+swap_id+"&ran="+Math.random();
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = show3;
xmlHttp.send();
}#其中的action.php不能有超出
if(isset($_GET['swap_id']])){……}
范围的其它输出,否则将被全部传回前端。
如果真接收一个页面还不如从新建一个页面来得快呢,Ajax在传送大数据量时也会慢的。
如果你还是要坚持接收页面,那可以将Ajax回调函数的内容改一下:function show3(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
var text = xmlHttp.responseText;
window.open(text); //此处为在新窗口打开text内容
}else {
alert("response error code:"+xmlHttp.status);
}
}
}