zoukankan      html  css  js  c++  java
  • AJAX入门1

    $(function () {
                $("#btnGetDate").click(function () {
                    var xhr;
                    //第一步:创建异步请求的核心的对象:
                    if (XMLHttpRequest) {
                        xhr = new XMLHttpRequest(); //运行:is8,ie9,chrom,ff
                    } else {//ie6  ie5.x
                        xhr = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    //第二步:设置请求对象跟后台哪个页面进行交互
                    //HTTP请求的方法名    请求的页面    是否是异步
                    //Get请求通过QueryString传递参数
                    // xhr.open("Get", "ProcessAjax.ashx?p=33", true);
                    xhr.open("Post", "ProcessAjax.ashx", true);               
                    //Post请求要设置一下此请求头部
                    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    //第三步:发送请求
                    //Post通过此来传递参数
                    xhr.send("ip=3&renp=100");
                    //第四步:后台返回数据后,会调用此方法,回调函数
                    xhr.onreadystatechange = function () {
                        //0:未初始化;1:打开;2:发送;3:正在接收
                        //4标识:前台已经接受完了后台发送来的响应报文
                        if (xhr.readyState == 4) {
                            alert(xhr.responseText);
                        }
                    };
                });
            });
    HTML代码:
     <input type="button" value="获取服务器端时间" id="btnGetDate"/>

    后台代码:

    context.Response.Write(DateTime.Now.ToString());
    Top
    收藏
    关注
    评论
  • 相关阅读:
    IOS7 About
    iOS Newsstand Tutorial
    微信开发商
    网络流量监控相关资料
    EDM about
    thinkphp验证码的实现
    thinkphp表单上传文件并将文件路径保存到数据库中
    thinkphp分页实现
    linux 系统简单备份
    Google Hacking总结
  • 原文地址:https://www.cnblogs.com/automation/p/2836044.html
Copyright © 2011-2022 走看看