qq_26722071 2019-11-21 21:30 采纳率: 0%
浏览 331

为啥接受不到数据AJAX

   <script src ="Js/jquery-3.4.1.js"> </script>
    <script>
        ////定义变量保存XmlHttpRequest对象 
        //var xmlHttp = null;
        ////用于创建AJAX请求核心对象XmlHttpRequest
        //function createXmlHttpRequest() {
        //    try
        //    {
        //        xmlHttp = new XMLHttpRequest();//适用于IE7+,Fireiox,Chrome等主流浏览器
        //    }
        //    catch (Error)
        //    {
        //        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//适用于IE低版本7以下的
        //    }

        //}


        //$(function () {
        //    $("#ImgButOn").click(function () {
        //        //调用函数创建XmlHttpRequest对象
        //        createXmlHttpRequest();

        //        //获得需要提交给服务器的数据
        //        var UserId = $("#TxtUser").val();
        //        var UserPwd = $("#TxtPwd").val();

        //        //服务端路劲,同时把数据传送到服务器地址拦
        //        var serverPath = "server.ashx?UserId=" + UserId + "&UserPwd=" + UserPwd + "";

        //        //设置XmlHttpRequest对象参数
        //        xmlHttp.open("get", serverPath, true);

        //        //服务端处理结果,使用XmlHttpRequest对象状态监测
        //        xmlHttp.onreadystatechange = clicentCallback;

        //        //通过XmlHttpRequest对象发送请求
        //        xmlHttp.send();
        //    })
        //})

        //function clicentCallback() {
        //    //XmlHttpRequest对象状态从开始发送请求到服务端经历了4个分别是:
        //    //返回值 0 :请求位初始化
        //    //返回值 1 :和服务端连接已经建立
        //    //返回值 2 : 请求已被服务端接受
        //    //返回值 3 :请求处理中
        //    //返回值 4 :请求处理完
        //    if (xmlHttp.readyState == 4) {
        //        if (xmlHttp.status == 200) {
        //            //获得服务端返回给客户端的结果(纯文本,xml,josn,html)
        //            var msg = xmlHttp.responseText;
        //            alert(msg);

        //        }

        //    }


        //}


        //#Jquery封装函数使用AJAX异步请求

        $(function () {
            $("#ImgButOn").click(function () {
                $.ajax({
                    url:"server.ashx",//请求服务端地址
                    type:"get",//请求方式
                    data:{
                        "UserId": $("#TxtUser").val(),
                        "UserPwd":$("#TxtPwd").val()
                    }//发送到服务端的数据
                    success:function (date, status, xmlhttp) {//服务端成功处理时回调函数
                        alert(date + ":" + status);
                    },
                    error: function () {//服务端失败时的回调函数
                        alert("请求未成功!");
                    },

                    dataType:"text"//预期服务端发回数据类型
                    })
        })



    </script>



        public void ProcessRequest(HttpContext context)
        {
            SES_Model.User user = new SES_Model.User();
            //服务端要获得客户端以AJAX请求发送过来的数据
            string UserId = context.Request.QueryString["UserId"];
            string UserPwd = context.Request.QueryString["UserPwd"];


            //在服务器中处理数据

            user = SES_BLL.Users_Service.User_Enter(UserId, UserPwd);
            string msg = string.Empty;
            if (user != null)
            {
                msg = "ok";
            }
            else
            {
                msg = "error!";
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(null);
        }
  • 写回答

2条回答 默认 最新

  • threenewbee 2019-11-21 22:35
    关注

    fiddler或者浏览器抓包看下,请求发出没有,是否存在跨域问题,地址对不对,返回了什么。

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择