weixin_33713707 2017-06-27 13:35 采纳率: 0%
浏览 24

阿贾克斯不打电话

I am trying to call ajax then ajax will call ´WebMethod`, but my AJAX is not executed.

Here is HTML Code for the TextBox.TextChanged Event

<input id="usernamesignup" name="usernamesignup" required="required" type="text"  placeholder="User Name" runat ="server" onchange="checkUserName();"/>

and for AJAX I have written JavaScript function

function checkUserName()
    {
        debugger;
        $.ajax({

            type: "POST",
            async: true,
            url: "SignUp1.aspx/CheckUserNameAvailability",
            data: '{username: "'+ $("#<%=usernamesignup.ClientID%>").value.trim() +'" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
              var msg = $("#<%=LabelStatus.ClientID%>")[0];
                switch (response.d) {
                    case "true":
                        msg.style.display = "block";
                        msg.style.color = "red";
                        msg.innerHTML = "User Name Or Email already exists.";
                        break;
                    case "false":
                        msg.style.display = "block";
                        msg.style.color = "green";
                        msg.innerHTML = "User Name Or Email Available";
                        break;
                }

            }
        });

    }

and my WebMethod is

    [System.Web.Services.WebMethod]
    public static int CheckUserNameAvailability(string username)
    {
        string conString = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        using (MySqlConnection conn = new MySqlConnection(conString))
        {
            using (MySqlCommand cmd = new MySqlCommand("spCheckUserNameAvailability", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("UserName", username);
                conn.Open();
                return (int)cmd.ExecuteScalar();
            }
        }
    }

Please anyone suggest me some changes in this code to make it work

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8
      • ¥15 安卓时间管理APP,怎么做
      • ¥15 这段有什么bug 为什么总报错
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云