No need for new users to log on to the instance code, ajax User Login

Source: Internet
Author: User

No need for new users to log on to the instance code, ajax User Login

The code for logging on to an instance without refreshing new users implemented by ajax:
Functions such as refreshing new logon or submitting messages are becoming increasingly popular. If a website does not have any ajax application, it does not feel any technical level. Of course, this technology is actually not difficult, the following is an example of this Code, which is helpful for beginners.
The following code is added in segments:

 

<Table> <tr> <td> User Name: </td> <input type = "text" id = "username"/> </td> </tr> <td> password: </td> <input type = "text" id = "password"/> </td> </tr> <td> Verification Code: </td> <input type = "text" id = "cord"/>  </td> </tr> <td> <input type =" button "value =" Logon "/> </td> </td> </tr> </table>

 

The preceding section describes the logon information.
Ii. jQuery code:

 

Function login () {$. ajax ({url: 'login. ashx ', data: 'username =' + $ ("# username "). val () + "& password =" + $ ("# password "). val () + "& cord =" + $ ("# cord "). val (), type: 'post', error: function () {alert ("link server error! ") ;}, Success: function (msg) {alert (msg) ;}}) ;}// Verification Code image $ (function () {$ (" # username "). focus (); $ ("# checkcord "). click (function () {$ ("# checkcord "). attr ("src", "img. ashx? Time = "+ new Date ());})})

 

III. c # The background processing code is as follows:

Context. response. contentType = "text/plain"; string username = context. request. form ["username"]; string password = context. request. form ["password"]; string cord = context. request. form ["cord"]; if (context. session ["cord"]! = Null) {if (context. session ["cord"]. toString () = cord) {if (username = "admin" & password = "admin") {context. response. write ("Logon successful! ");} Else {context. Response. Write (" Logon Failed! Incorrect username and password! ") ;}} Else {context. Response. Write (" Verification code error! ");}}

The above code is very simple. You don't need to talk about it here. You just need to refer to the following basic concepts.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9272.

For more information, see: http://www.softwhy.com/jquery/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.