Use jQuery to simplify ajax operation instance code
Copy to ClipboardReference: [www.bkjia.com] <% @ Page Language = "C #" ContentType = "text/html" ResponseEncoding = "gb2312" %>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
If (Request. Form ["name"]! = Null)
{
System. Threading. Thread. Sleep (3000 );
Response. Write (Request. Form ["name"] + ": Hello, asynchronous data transmission is successful! ");
Response. End ();
}
}
}
</Script>
<Html>
<Head runat = "server">
<Title> Untitled Page </title>
<Style type = "text/css">
Body {font-size: 12px; line-height: 30px ;}
</Style>
<Script type = "text/javascript" src = "jquery. js"> </script>
<Script type = "text/javascript">
// Submit data
Function ajax (){
$. Post (
"Index. aspx ",
{
Name: "Dear friend"
},
Function (data ){
$ ("# DivData"). text (data );
}
)
}
$ (Document). ready (function (){
// Start the request
$ ("# Jindu"). ajaxStart (function (){
$ ("# DivData" ).html (null );
$ (This). show ();
});
// When the request ends
$ ("# Jindu"). ajaxStop (function (){
$ (This). hide ();
});
});
</Script>
</Head>
<Body>
<Input id = "Button1" type = "button" value = "asynchronous communication test" onclick = "ajax ();"/>
<Div id = "divData"> </div>
<Div id = "jindu" style = "display: none;"> data is being submitted. Please wait... </Div>
</Body>
</Html>