Code for asynchronous refresh Based on JQuery

Source: Internet
Author: User

Today, we will briefly introduce this encapsulated call.
Example:
Call page: JqueryTest. aspx (Note: No code in the background)
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "JqueryTest. aspx. cs" Inherits = "XmlHttpRequestTest. JqueryTest" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Script src = "JS/jquery-1.4.2.js" type = "text/javascript"> </script>
<Script language = "javascript">
Function test (){
$. Ajax ({
Type: "POST ",
Url: "JqueryService. aspx ",
Data: "userName = 123 & password = 456 ",
Success: function (data ){
If (data = "true "){
Alert ("Login successful! ");
}
Else {
Alert ("Logon Failed ");
}
}
});
}
Function btntestajax_onclick (){
Test ();
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Input id = "btntestajax" type = "button" value = "test asynchronous refresh" onclick = "return btntestajax_onclick ()"/> </div>
</Form>
</Body>
</Html>

Called interface: JqueryService
Front-end:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "JqueryService. aspx. cs" Inherits = "XmlHttpRequestTest. JqueryService" %>
Background:
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Namespace XmlHttpRequestTest
{
Public partial class JqueryService: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
String userName = Request. Form ["userName"]. ToString ();
String password = Request. Form ["password"]. ToString ();
If (userName. Equals ("123") & password. Equals ("456 "))
{
Response. Write ("true ");
}
Else
{
Response. Write ("false ");
}
}
}
}

Note: Because the code is too simple and not detailed, please refer to relevant materials if you do not understand it.

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.