我是处理 XML 响应数据的新手。我有一个 Web 服务,它检查 SQL 服务器数据库中的用户和他的密码并相应地返回响应。Web服务方法的代码如下;
<WebMethod()> _
Public Function Authentication(ByVal username As String, ByVal password As String) As String
'Public Function ConnectToSQL() As String
Dim con As New SqlConnection
Dim result As Boolean
Dim response As String
Try
con.ConnectionString = "Data Source=TestServer;Initial Catalog=MyDB;Persist Security Info=True;User ID=myuser;Password=mypass"
Dim cmd As New SqlCommand("SELECT username FROM user_detail WHERE username='" + username + "' AND password='" + password + "'", con)
con.Open()
' Execute Query
Dim reader As SqlDataReader = cmd.ExecuteReader()
result = reader.HasRows
'Validate user info from database
If result = True Then
response = "Valid user info..Thanks"
Else
response = " Not valid user info..Please Enter again, Thanks"
End If
If Not reader Is Nothing Then
reader.Close()
End If
Catch ex As Exception
MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
Finally
con.Close() 'Whether there is error or not. Close the connection.
End Try
Return response
End Function
End Class
响应为 XML 数据,如下图所示。(如果输入了有效的用户信息)
现在我想在 Javascript 中创建一个视图,它从用户那里获取输入,然后通过这个 Web 服务从数据库中验证用户信息。有人可以帮我怎么做吗?