zoukankan      html  css  js  c++  java
  • Ajax异步请求-简单模版

     1 <script type="text/javascript">
     2         window.onload = function () {
     3             document.getElementById("time").onclick = function () {
     4                 //向服务器请求时间
     5                 //1. 创建异步对象(相当与一个小浏览器)
     6                 var xhr = new XMLHttpRequest();
     7                 //2. 设置参数(请求方式,请求哪个页面,是否异步)
     8                 xhr.open("get", "Ajax.ashx", true);
     9                 //如果不想让浏览器不拿缓存数据,每次请求都会到服务器拿数据,如下设置
    10                 xhr.setRequestHander("If-Modified-Since","0");
    11                 //3. 设置回调函数
    12                 xhr.onreadystatechange = function () {
    13                     if (xhr.readyState == 4 && xhr.status == 200) {
    14                         var res = xhr.responseText;
    15                         alert(res);
    16                     }
    17                 }
    18 
    19                 //4. 发送异步请求
    20                 xhr.send(null);
    21             }
    22         }
    23     </script>
    ajax异步请求,请求服务器时间
  • 相关阅读:
    C#:反射
    静态和非静态类
    数据的存入取出(注册机方式)
    退出unity运行
    网络流基础
    欧拉回路
    博弈论问题
    洛谷P5304 [GXOI/GZOI2019] 旅行者
    [ZJOI2006]物流运输
    POJ3278 Catch that cow
  • 原文地址:https://www.cnblogs.com/liyajie/p/ajax.html
Copyright © 2011-2022 走看看