HTTP协议
传统的请求和Ajax请求
Ajax定义
Asynchronous JavaScript and XML. Ajax异步的,JavaScript程序希望与服务器直接通信而不需要重新加载页面。
Ajax基本流程
1.创建请求对象
functionrequestObject(){ if(window.XMLHttpRequest){ returnnewXMLHttpRequest(); }elseif{ returnnewActiveXObject('Mxsml2.XMLHTTP'); }else{ thrownewError("CouldnotcreateHTTPrequestobject."); } }
2.建立请求
var request=requestObject();
request.open("GET","data.txt",true);
3.发送请求
request.send(null);
4.处理请求(XML和JSON两种格式)
request.onreadystatechange=function(){if(request.readyState==4){console.log(request.status+":"+request.statusText); } }原文链接:https://www.f2er.com/ajax/161135.html