本文介绍了jQuery用户名可用性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在空白文本框上,jQuery用户名可用性显示为"Available",我正在检查按键事件中的可用性.

我的代码是

on blank textbox Jquery username availability showing "Available" i''m cheking availability on keyup event.

my code is

[System.Web.Services.WebMethod]
    public static string CheckUserName(string userName)
    {
        string returnValue = string.Empty;
        try
        {
            string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
            SqlConnection Sqlconn = new SqlConnection(SqlConnect);
            SqlCommand cmd = new SqlCommand("spx_CheckUserAvailability",Sqlconn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserName", userName.Trim());
            Sqlconn.Open();
            returnValue = cmd.ExecuteScalar().ToString();
            Sqlconn.Close();
        }
        catch
        {
            returnValue = "error";
        }
        return returnValue;
    }



源代码部分-



source part-

<script src="js/jquery-1.3.2.min.js"type="text/javascript"></script>



      <script type = "text/javascript">
     function ShowAvailability() {

    $.ajax({
        type: "POST",
        url: "Signup.aspx/CheckUserName",
        data: '{userName: "' + $("#<%=TextBox4.ClientID%>")[0].value + '" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert(response);
        }
    });
}

function OnSuccess(response) {
    var mesg = $("#mesg")[0];

    switch (response.d) {
        case "true":
            mesg.style.color = "green";
            mesg.innerHTML = "<img src='image/tick.png' width='13px' height='13px'> Available";

            break;
        case "false":
            mesg.style.color = "red";
            mesg.innerHTML = "<img src='image/unavailable.png' width='13px' height='13px'> Not Available";
            break;
        case "error":
            mesg.style.color = "red";
            mesg.innerHTML = "Error occured";
            break;
//        case  "null":
//            mesg.style.color="black";
//            mesg.innerHTML="Fill email ID";
//            break;                     
    }
}
function OnChange(txt) {
   $("#mesg")[0].innerHTML = "";
}
</script> 

推荐答案




这篇关于jQuery用户名可用性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:35