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或者浏览器抓包看下,请求发出没有,是否存在跨域问题,地址对不对,返回了什么。

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘