8

1、Ajax(读A—jax不是阿贾克斯)原理图:clipboard.png

clipboard.png

clipboard.png

2、HTTP请求概念

clipboard.png

clipboard.png

clipboard.png

clipboard.png

<script>
document.getElementById("search").onclick = function() { 
   var request = new XMLHttpRequest();
   request.open("GET", "server.php?number=" + document.getElementById("keyword").value);
   request.send();
   request.onreadystatechange = function() {
      if (request.readyState===4) {
         if (request.status===200) { 
            document.getElementById("searchResult").innerHTML = request.responseText;
         } else {
            alert("发生错误:" + request.status);
         }
      } 
   }
}

document.getElementById("save").onclick = function() { 
   var request = new XMLHttpRequest();
   request.open("POST", "server.php");
   var data = "name=" + document.getElementById("staffName").value 
                     + "&number=" + document.getElementById("staffNumber").value 
                     + "&sex=" + document.getElementById("staffSex").value 
                     + "&job=" + document.getElementById("staffJob").value;
   request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   request.send(data);
   request.onreadystatechange = function() {
      if (request.readyState===4) {
         if (request.status===200) { 
            document.getElementById("createResult").innerHTML = request.responseText;
         } else {
            alert("发生错误:" + request.status);
         }
      } 
   }
}
</script>

clipboard.png
3、JSON语法规则

clipboard.png

4、jQuery实现Ajax

clipboard.png

clipboard.png

5、跨域

clipboard.png

clipboard.png


Bohr
6.5k 声望3.3k 粉丝