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.