1

我正在开发一个基本上是注册页面的应用程序。我想通过检查数据库中现有的电子邮件 ID 来停止重复注册。我使用 JQuery $.get() 方法在后台查询页面,然后获取现有或未退出电子邮件的结果。该页面在本地运行完美,但在线时,它会"503 Service Unavailable"在输入重复的电子邮件 ID 时返回。

jQuery方法如下:

<script type="text/javascript">
$(document).ready(function () {
    $("#ctl00_ContentPlaceHolder1_tbEmail").change(function () {
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var emailaddressVal = $("#ctl00_ContentPlaceHolder1_tbEmail").val()
        if(!emailReg.test(emailaddressVal)) {
            $("#msgbox").html('Invalid Email ID');
        return;
    }
        $("#ctl00_ContentPlaceHolder1_hidYorN").val("")
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
        $.get("scripts/email_availibility.aspx", { user_name: $(this).val() }, function (data) {
            if (data == 'no') 
            {
                $("#msgbox").fadeTo(200, 0.1, function () 
                {
                    $(this).html('This mail id is already registered!').addClass('messageboxerror').fadeTo(900, 1);
                    $("#ctl00_ContentPlaceHolder1_hidYorN").val("N");
                });
            }
            else {
                $("#msgbox").fadeTo(200, 0.1, function ()  
                {
                    $(this).html('You are welcome to register!').addClass('messageboxok').fadeTo(900, 1);
                    $("#ctl00_ContentPlaceHolder1_hidYorN").val("Y");
                });
            }
        });
    });
});
</script>

还有我的 aspx 页面代码(email_availibility.aspx):

string con = ConfigurationManager.ConnectionStrings["myDB"].ConnectionString.ToString();
protected void Page_Load(object sender, EventArgs e)
{
    string data = "no";
    OleDbConnection conn = new OleDbConnection(con);
    string user_name = Request.QueryString["user_name"];
    string strQury = "Select [EmailID] from [RegisterTable] where [EmailID]='" + user_name + "'";
    OleDbCommand cmds = new OleDbCommand(strQury, conn);
    OleDbDataReader dr;
    if (conn.State == ConnectionState.Closed)
        conn.Open();
    dr = cmds.ExecuteReader();
    if (dr.HasRows)
    {
        data = "no";
    }
    else
    {
        data = "yes";
    }
    if (conn.State == ConnectionState.Open)
        conn.Close();
   Response.Write(data);
}

我不太习惯JQuery,刚开始,所以请简单回答

4

0 回答 0