| |

VerySource

 Forgot password?
 Register
Search
View: 751|Reply: 5

Who has Ajax source code to verify user names in Asp.net (c #) in real time (to read data from the database)

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-19 10:20:01
| Show all posts |Read mode
I want to learn, the code is simple and the best
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-28 18:54:01
| Show all posts
I don't understand what you mean, but I have, use ajax to do the login code, for your reference.
Here is the generic js script:
// JScript file, 2006-05-15--chx
// Public operations for ajax
 function createRequestObject () // Create XMLHttpRequest object
    {
    var xmlhttp_request = null;
    try {
          if (window.ActiveXObject)
          {
               for (var i = 5; i; i--)
               {
                 try {
                          if (i == 2)
                          {
                             xmlhttp_request = new ActiveXObject ("Microsoft.XMLHTTP");
                          }
                          else
                          {
                              xmlhttp_request = new ActiveXObject ("Msxml2.XMLHTTP." + i + ".0");
                              xmlhttp_request.setRequestHeader ("Content-Type", "text / xml");
                              xmlhttp_request.setRequestHeader ("Content-Type", "GB2312");
                           }
                           break;
                    }
                    catch (e)
                    {
                            xmlhttp_request = null;
                     }
                 }
            }
            else if (window.XMLHttpRequest)
            {
                   xmlhttp_request = new XMLHttpRequest ();
                   if (xmlhttp_request.overrideMimeType)
                   {
                       xmlhttp_request.overrideMimeType ('text / xml');
                       //xmlhttp_request.overrideMimeType('GB2312 ');
                    }
             }
       }
       catch (e)
       {
           xmlhttp_request = null;
        }
        return xmlhttp_request;
}
// Send an asynchronous request
function SendRequest (method, url, data, callback, isasyn) // callback This function gets the asynchronous return information and displays it, dada is a string
{
    var xmlhttp = createRequestObject ();
    with (xmlhttp)
    {
        try
        {
            // add random numbers to prevent caching
            if (url.indexOf ("?")> 0)
            {
                url + = "&randnum =" + Math.random ();
            }
            else
            {
               url + = "? randnum =" + Math.random ();
            }

            open (method, url, isasyn);

            // Set the request encoding method
            // setRequestHeader ('Content-Type', 'application / x-www-form-urlencoded; charset = UTF-8');
            setRequestHeader ('Content-Type', 'application / x-www-form-urlencoded; charset = GB2312');
            if (data! = "")
            {
               send (data);
            }
            else
            {
               send ();
            }
            onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4) // determine whether the asynchronous call was successful
                {
                   callback (xmlhttp);
                   xmlhttp = null;
                }
            }
        }
        catch (e)
        {
           alert (e);
        }
    }
}
Here is the actual code:
<script type = "text / javascript" src = "../ JScript / ajax.js"> </ script>
<script type = "text / javascript">
    var serid = "";
    function checkuser (object)
    {
       var thisid = object.id;
       serid = thisid.substring (0, thisid.lastIndexOf ('_'));
       public_getElementByID (serid + "_ ibtmLogin"). style.display = "none";
       public_getElementByID ("divlogin"). innerHTML = "Login ... <br/> <img width = '170' src = '.. / Images / loader.gif' />";
       var user = public_getElementByID (serid + "_ txtUserName"). value;
       var pass = public_getElementByID (serid + "_ txtPassWord"). value;
       SendRequest ("POST", "../ Pages / Check.aspx? Loginuser =" + user + "&pass =" + pass + "," ", checkok, true);
    }
    
    function checkok (http)
    {
        var response = http.responseText; // return the server-generated string
        if (response == "Successful login")
        {
             public_getElementByID ("divlogin"). innerHTML = response;
             window.location.href = "../ Default.aspx"
             return;
        }
        else
        {
          alert (response);
          public_getElementByID (serid + "_ ibtmLogin"). style.display = "block";
          public_getElementByID ("divlogin"). innerHTML = "";
        }
    }
 </ script>
Explanation: public_getElementByID () is my method that supports ec and ie, equivalent to document.getElementByID ().
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-28 21:00:02
| Show all posts
// Code after removing project specific requirements
<script type = "text / javascript" src = "../ JScript / ajax.js"> </ script>
<script type = "text / javascript">
    var serid = "";
    function checkuser (object)
    {
       public_getElementByID ("ibtmLogin"). style.display = "none"; // Hide the login button
       public_getElementByID ("divlogin"). innerHTML = "Login ... <br/> <img width = '170' src = '.. / Images / loader.gif' />"; // Show login in progress
       var user = public_getElementByID ("txtUserName"). value;
       var pass = public_getElementByID ("txtPassWord"). value;
       SendRequest ("POST", "../ Pages / Check.aspx? Loginuser =" + user + "&pass =" + pass + "," ", checkok, true);
    }
    
    function checkok (http)
    {
        var response = http.responseText; // return the server-generated string
        if (response == "Successful login")
        {
             public_getElementByID ("divlogin"). innerHTML = response;
             window.location.href = "../ Default.aspx"
             return;
        }
        else
        {
          alert (response);
          public_getElementByID ("ibtmLogin"). style.display = "block";
          public_getElementByID ("divlogin"). innerHTML = "";
        }
    }
 </ script>
Reply

Use magic Report

2

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-31 08:09:01
| Show all posts
mark
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-9 09:30:01
| Show all posts
Not bad.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-14 21:45:01
| Show all posts
So it turns out
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list