ajax跨域调用一般处理程序 传参问题

前台代码

$("#submitbut").click(function(){
               var phonetel = $("#phonetel").val();
               var Purl = "http://www.cuplmsy-edu.cn/bmStudent.ashx?phone=" + phonetel;
               if (phonetel != '' && isPhoneNo(phonetel))
               {
                   $.ajax({
                       type: "get",
                       url: Purl,
                       success: function (e) {
                           if (e == 1) {
                               alert("报名成功!");
                               $("#phonetel").val("");
                           } else {
                               //alert("抱歉,请重新输入手机号!");
                           }
                       },
                       error: function (e) {
                           alert("网络错误");
                       }
                   })
               } else {
                   alert("电话格式错误,请重新输入")
               }
           })

 

后台代码 (bmStudent.ashx)

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";

            string username = context.Request.QueryString["phone"];

            Nankai.Model.Enroll enroll = new Nankai.Model.Enroll();
            enroll.CellPhone = username;

            Nankai.BLL.Enroll enrollBLL = new Nankai.BLL.Enroll();
            try
            {
                int num = enrollBLL.Add(enroll);
                if (num > 0)
                {
                    context.Response.Write("1");
                }
                else
                {
                    context.Response.Write("0");
                }
            }
            catch (Exception)
            {
                context.Response.Write("0");
            }
        }

 

你可能感兴趣的:(javascript,C#-ASPX-EF,html,ajax,跨域,一般处理程序)