AJAX问题求助
时间:2010-09-25
来源:互联网
我按老师讲的写了个AJAX文件可是效果出不来。请大家帮忙看一下:
AJAX.JS文件:
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function funphp100(url){
S_xmlhttprequest();
XMLHttp.open("GET","for.php?id="+url,true);
XMLHttp.onreadystatechange=byphp;
xmlHttp.send(null);
}
ffunction byphp(){
if(xmlHttp.readyState==1){
document.getElementById('php100').innerHTML="lodin.....";
}
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var byphp100=xmlHttp.responseText;
document.getElementById('php100').innerHTML=byphp100;
}
}
}
输出页文件index.php
<script language="javascript" src="ajax.js"></script>
<a href="#" onclick=funphp100('a') >a</a>
<a href="#" onclick=funphp100('b')>b</a>
<a href="#" onclick=funphp100('c')>c</a>
<div id="php100"></div>
for.php文件是没有问题的我测试过了。
AJAX.JS文件:
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function funphp100(url){
S_xmlhttprequest();
XMLHttp.open("GET","for.php?id="+url,true);
XMLHttp.onreadystatechange=byphp;
xmlHttp.send(null);
}
ffunction byphp(){
if(xmlHttp.readyState==1){
document.getElementById('php100').innerHTML="lodin.....";
}
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var byphp100=xmlHttp.responseText;
document.getElementById('php100').innerHTML=byphp100;
}
}
}
输出页文件index.php
<script language="javascript" src="ajax.js"></script>
<a href="#" onclick=funphp100('a') >a</a>
<a href="#" onclick=funphp100('b')>b</a>
<a href="#" onclick=funphp100('c')>c</a>
<div id="php100"></div>
for.php文件是没有问题的我测试过了。
作者: baiping588 发布时间: 2010-09-25
XMLHttp.onreadystatechange=byphp();要加括号才是调用js方法
作者: yunjian 发布时间: 2010-09-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28