使用Jquery远程方法,SQL和ASP.net网络表单进行用户名验证

时间:2018-10-10 04:06:18

标签: jquery asp.net json vb.net

我有一个ASP.NET网络表单,用于检查数据库中是否存在用户名。我正在尝试将TRUE / False值传递给jQuery以显示成功/错误类,但是我在使其正常工作时遇到问题-以下错误消息。有任何想法吗?不幸的是,我不能使用MVC。任何帮助将不胜感激!

Error Message

VB.NET

Public Function username_validate() As String
    Dim con As New OleDbConnection
    Dim serial As New JavaScriptSerializer()
    con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database\testing.mdb")
    con.Open()
    Dim sql As String = "SELECT DISTINCT USERNAME FROM PERSLOGIN WHERE PERSNBR = 1001"
    Dim cmd As New OleDbCommand(sql, con)
    Dim i As Integer = 0
    Dim ds As New DataSet
    Dim da As New OleDbDataAdapter(cmd)

    da.Fill(ds, "username")

    'firstname.Text = ds.Tables("username").Rows(i)(0).ToString().ToLower()

    Dim db_username As String = ds.Tables("username").Rows(i)(0).ToString().ToLower()

    If emailaddress.Text.ToLower() = db_username Then Return serial.Serialize(True) Else Return serial.Serialize("")

End Function

jQuery:

$("#register").validate({



        emailaddress: {
            required: true,
            remote: "username_validation"

        },


    messages: {

        emailaddress: {
            required: 'You must enter a valid email address!',
            remote: 'Username already exists!'



        }
    }
});

0 个答案:

没有答案