AJAX
介绍
:
AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式
网页应用的网页开发技术。异步无刷新
localhost / 127.0.0.1
AJAX 基础步骤详解
:
1.var xhr = new XMLHttpRequest();
声明一个XMLHttpRequest对象,所有的AJAX的操作,都是基于这个对象本身的。var xhr = null;If(window.XMLHttpRequest){
xhr = new XMLHttpRequest()
}else {
xhr = new ActiveXObject('Microsoft.XMLHTTP')
}
try{
xhr = new XMLHttpRequest()
}catch(e){
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
2.xhr.open('get','readme.txt',true);
设置通过什么方式去获取文件内容,并且设置要操作的文件,设置是异步还是同步xhr.open(method,url,asyn);method : get / post
3.xhr.send();
发送请求
4.xhr.onreadystatechange = function(){}
监听请求状态
5.if(xhr.readyState == 4){}
对服务器状态的判断 readyState == 4
6.xhr.responseText
拿走请求的内容