Σε μια φόρμα εγγραφής πελάτη προσπαθώ να κάνω έλεγχο με ajax στη βάση αν υπάρχει ήδη καταχωρημένο το email ή όχι.
Το javascript είναι
Κώδικας: Επιλογή όλων
<script language="javascript">
$(document).ready(function()
{
$("#NewfileName").blur(function()
{
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
$.post("check1.aspx",{ NewfileName:$(this).val() } ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
$(this).html('Το όνομα αρχείου υπάρχει!!!').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('OK').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
});
</script>
Κώδικας: Επιλογή όλων
<input name="NewfileName" id="NewfileName" size="93" style="border:1px solid #B5C3D6" value="">
<span id="msgbox" style="display:none"></span>
Κώδικας: Επιλογή όλων
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlTypes" %>
<%@ Import Namespace="Shop" %>
<script runat="server">
Private NewEmail As String
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim command As SqlCommand = New SqlCommand()
command.CommandType = CommandType.Text
command.CommandText = "SELECT Email FROM Customers WHERE Email=@NewEmail"
command.Parameters.Add(New SqlParameter("@NewEmail", SqlDbType.NVarChar)).Value = CStr(Request.Form("NewfileName"))
command.Connection = DB.GetConnection()
Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
Dim dataTable As DataTable = New DataTable()
adapter.Fill(dataTable)
If dataTable.Rows.Count = 0 Then
Response.Write("yes")
Else
Response.Write("no")
End If
End Sub
</script>
Τώρα με την asp.net έλεγχο κάτι δε κάνω σωστά.
Το script to έχω πάρει απο εδώ.
http://roshanbh.com.np/2008/04/check-us ... query.html