Jquery and asp.net
Last Update:2018-12-07
Source: Internet
Author: User
<Body>
<Form id = "form1" runat = "server">
<Div id = "divguid"> </div>
<Div id = "lblDataUpdated">
</Div>
<Div id = "lblMinute"> </div>
<Script type = "text/javascript">
$ (Document ). ready (function () {$ ('# loading '). hide (); $ ('# clickmeupdate '). click (function () {MyUpdate ();});});
Function MyUpdate ()
{
$ ('# Loading'). show ();
Var name = $ ('# tbname'). val ();
Var password = $ ('# tbpassword'). val ();
$. Post ("ajaxdata. ashx", {name: name, word: password}, function (result)
{
Var oResultData = eval ('+ result + ')');
Certificate ('{divguid'}.html (oResultData. realname );
Certificate ('audio lbldataupdated'audio .html (oResultData. sex );
('{Lblminute'{.html (oResultData. email );
$ ('# Loading'). hide ();
});
// SetTimeout (MyUpdate, 10*1000 );
}
</Script>
<Br/>
<Table class = "style1">
<Tr>
<Td>
User name </td>
<Td>
<Asp: TextBox ID = "tbName" runat = "server"> </asp: TextBox>
</Td>
</Tr>
<Tr>
<Td>
Password </td>
<Td>
<Asp: TextBox ID = "tbPassWord" runat = "server"> </asp: TextBox>
</Td>
</Tr>
</Table>
<Input type = "button" id = "clickmeupdate" value = "Submit"/>
</Form>
</Body>
Server Section
Public class ResultData
{
Public string User_realname;
Public string User_sex;
Public string User_email;
Public ResultData ()
{
HttpContext context = HttpContext. Current;
String name = context. Request ["name"];
String password = context. Request ["word"];
String SQL = "select * from z_UserInfo where User_name = @ name and User_psw = @ password ";
// Minute = DateTime. Now. Minute;
// Guid = System. Guid. NewGuid (). ToString ();
// Updated = DateTime. Now;
String conn = "Data Source =.; Initial Catalog = shop; uid = sa; pwd = sa ";
SqlConnection connection = new SqlConnection (conn );
SqlCommand com = new SqlCommand (SQL, connection );
SqlParameter p1 = new SqlParameter ("@ name", DbType. String );
P1.Value = name;
Com. Parameters. Add (p1 );
SqlParameter p2 = new SqlParameter ("@ password", DbType. String );
P2.Value = password;
Com. Parameters. Add (p2 );
Connection. Open ();
SqlDataReader reader = com. ExecuteReader ();
While (reader. Read ())
{
User_realname = reader ["User_realname"]. ToString ();
User_sex = reader ["User_sex"]. ToString ();
User_email = reader ["User_email"]. ToString ();
}
Connection. Close ();
}
Public string GetResultDataJSON ()
{
StringBuilder oBuilder = new StringBuilder ();
OBuilder. Append ("{");
OBuilder. AppendFormat ("{0}: '{1}',", "realname", User_realname );
OBuilder. AppendFormat ("{0}: '{1}',", "sex", User_sex );
// Datetime special-javascript date is MS after 1 jan 1970
// TimeSpan oSpan = Updated-new DateTime (1970, 1, 1, 0, 0, 0 );
OBuilder. AppendFormat ("{0}: '{1}'", "email", User_email );
OBuilder. Append ("}");
Return oBuilder. ToString ();
}
}
Context. Response. Cache. SetCacheability (HttpCacheability. NoCache );
Context. Response. ContentType = "text/plain ";
// If (context. Request ["what"]! = Null & context. Request ["what"] = "resuldata ")
Context. Response. Write (new ResultData (). GetResultDataJSON ());