标签:成功 fun 获取 object 浏览器 html 内容 lis 处理
局部刷新技术。不是一门新技术,是多种技术的组合。是浏览器端的技术。
实现在当前结果页中显示其他请求的响应内容
创建ajax引擎对象
复写onreadystatement函数
json格式:
var 对象名={
属性名:属性值,
属性名:属性值,
……
}
发送请求
ajax的状态码
ajax的异步和同步
<script type="text/javascript">
function getData(){
//创建ajax引擎对象
var ajax;
if(window.XMLHttpRequest){//火狐
ajax=new XMLHttpRequest();
}else if(window.ActiveXObject){//ie
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}
//复写onreadystatement函数
ajax.onreadystatechange=function(){
//判断Ajax状态吗
if(ajax.readyState==4){
//判断响应状态吗
if(ajax.status==200){
//获取响应内容
var result=ajax.responseText;
//处理响应内容
//获取元素对象
var showdiv=document.getElementById("showdiv");
showdiv.innerHTML=result;
}else if(ajax.status==404){
//获取元素对象
var showdiv=document.getElementById("showdiv");
showdiv.innerHTML="请求资源不存在";
}else if(ajax.status==500){
//获取元素对象
var showdiv=document.getElementById("showdiv");
showdiv.innerHTML="服务器繁忙";
}
}else{
//获取元素对象
var showdiv=document.getElementById("showdiv");
showdiv.innerHTML="<img src=‘img/2.gif‘ width=‘200px‘ height=‘100px‘/>";
}
}
//发送请求
ajax.open("get","ajax",true);
ajax.send(null);
alert("哈哈");
}
</script>
标签:成功 fun 获取 object 浏览器 html 内容 lis 处理
原文地址:https://www.cnblogs.com/Scorpicat/p/12394738.html