1.ajax作用: ajax是用来局部刷新的,其实就是代替了form action
ajax的核心对象是XMLHttpRequest(异步对象)
2.ajax步骤:
1)创建异步对象 var xmlHttp=new XMLHttpRequest();
2)给异步对象绑定事件:onreadystatechange:当异步对象发起请求,获取了数据都会触发
如:xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState4 &&xmlHttp.status200){
//开始处理数据var data=xmlHttp.responseText;
//更新页面
}
}
3)初始化异步请求对象 xmlHttp.open(“get”,String url,true)
4)异步对象发送请求: xmlHttp.send()