Use jQuery to simplify ajax operation instance code

Source: Internet
Author: User

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>

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.