Ajax概念、HTTP请求概念、Ajax的原生和jQuery实现、跨域知识

前端之家收集整理的这篇文章主要介绍了Ajax概念、HTTP请求概念、Ajax的原生和jQuery实现、跨域知识前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

2、HTTP请求概念

<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>


3、JSON语法规则

4、jQuery实现Ajax

5、跨域

原文链接:https://www.f2er.com/ajax/161381.html

猜你在找的Ajax相关文章