- Ajax
ajax核心:XMLHttpRequest对象。无需刷新页面即可从服务器取得数据。
- 创建XMLHttpRequest对象。
var xml=new XMLHttpRequest();
- XMLHttpRequest的用法
xml.open("get","example.php",false);
首先调用open()方法,接受的三个参数值:要发送的请求类型(get,post等),请求的URL,是否异步发送请求的布尔值。此时,会启动针对example.php的get请求。
- send() 接受一个参数:作为请求主体发送的数据。null为不需要请求主体发送数据。在收到响应后,响应数据会自动填充xml对象的属性:responseText,responseXML,status(http响应状态码),statusText(http状态说明).
1 <script type="text/javascript"> 2 ????var xml=new XMLHttpRequest(); 3 ????xml.open("get","1.html",false); 4 ????xml.send(null); 5 ????if(xml.status>=20&&xml.status<300||xml.status==304){ 6 ????????alert(xml.responseText); 7 ????}else{ 8 ????????alert(xml.status); 9 ????}10 </script>
Ajax
原文地址:https://www.cnblogs.com/alaner/p/9526227.html