# AJAX
## 1、什么是AJAX
> AJAX是前端技術,是在不重新加載整個頁面的情況下與服務器交換數據并更新部分網頁的藝術.
>
> ```
> <script>
> window.onload=function(e){
> var butn = document.querySelector("button");
> btn.onclick=function(ev1){
> //1、創建一個異步對象
> var xmlhttp=new XMLHttpRequest();
> //2、設置請求方式和請求地址
> //open(method,url,async)
> //method:GET/POST url:文件在服務器上的位置 async:true(異步)/false(同步)
> xmlhttp.open("GET","XXX.php",true);
> //3、發送請求
> xmlhttp.send();
> //4、監聽狀態的變化
> xmlhttp.onreadystatechange = function(){
> //判斷是否請求成功
> if(xmlhttp.status >=200 && xmlhttp.status < 300 || xmlhttp.status === 305){
> //5、處理返回的結果
> if(xmlhttp.readyState===4){
> console.log("接收到服務器返回的數據");}
> }else{
> console.log("未接收到服務器返回的數據");
> }}
>
> }
> }
> </script>
> ```
>
>