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/