求助:ajax为什么不能用
时间:2010-06-03
来源:互联网
php100中的视频48中的例子,我完全按照上面的代码写的 为什么点击链接时说明效果都没有。而且我电脑上运行其他的有关Ajax的例子都没有效果,JavaScript可以运行。错我的原因是始终xmlhttp.readyState==1
var xmlHttp;
function $_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XmlHttpRequest();
}
}
function funphp(url){
//alert(url);
$_xmlhttprequest();
xmlHttp.open("GET","for.php?id=".url,true);
byphp();
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(null)
}
function byphp(){
alert(xmlhttp.readyState);
if(xmlhttp.readyState == 4 && (xmlhttp.status == 200||xmlhttp.status == 0)){
var byphp100=xmlHttp.responseText;
document.getElementById('php100').innerHTML=byphp100;
}else{
alert(1);
}
}
<script type="text/javascript" src="ajax.js"></script>
<a href="#" onclick="funphp('o')">o</a>
<a href="#" onclick="funphp('t')">t</a>
<a href="#" onclick="funphp('x')">x</a>
<div id="php100"></div>
<?php
$id=$_GET[id];
for($a=1;$a<10;$a++){
echo $id;
}
exit();
?>
这是所有代码
var xmlHttp;
function $_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XmlHttpRequest();
}
}
function funphp(url){
//alert(url);
$_xmlhttprequest();
xmlHttp.open("GET","for.php?id=".url,true);
byphp();
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(null)
}
function byphp(){
alert(xmlhttp.readyState);
if(xmlhttp.readyState == 4 && (xmlhttp.status == 200||xmlhttp.status == 0)){
var byphp100=xmlHttp.responseText;
document.getElementById('php100').innerHTML=byphp100;
}else{
alert(1);
}
}
<script type="text/javascript" src="ajax.js"></script>
<a href="#" onclick="funphp('o')">o</a>
<a href="#" onclick="funphp('t')">t</a>
<a href="#" onclick="funphp('x')">x</a>
<div id="php100"></div>
<?php
$id=$_GET[id];
for($a=1;$a<10;$a++){
echo $id;
}
exit();
?>
这是所有代码
[ 此帖被超越rock在2010-06-06 19:33重新编辑 ]
作者: 超越rock 发布时间: 2010-06-03
把代码贴出来。看看帮你看看。肯定是你的js文件有问题。
作者: dear.224 发布时间: 2010-06-04
你好 我也遇到了你这个问题 你现在解决了么 告诉我下呗 嘿嘿
作者: 114708367 发布时间: 2010-10-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28