ajax与传统web的区别
传统web应用:客户端浏览器提交请求-------服务端---------响应
ajax:客户端------ajax引擎(xmlhttprequest)----------服务器端
IE早起内置引擎为activexobject
创建ajax步骤
1:创建xmlhttprequest对象
- varxhr=newxmlhttprequest;
2:打开open 函数
- xhr.open(“post/get”,URL,true/false)true代表异步,false为同步
3:处理响应
- xhr.onreadstatechange=function(){
- if(xhr.readystate==4){
- if(xhr.status=200){
- vartxt=xhr.responTest;(字符串类型)//eval转换函数
- }
- }
- }
4.发送
- xhr.send(null);//get
- //post
- 1.设置请求头
- xhr.setRequestHeader("content-Type","appliation/x-www-form-urlencoder");
- 2.发送参数
- xhr.send(json格式数据)