Ajax in jquery
1. jqueryDOM. load ()
2. $. get ()
3. $. post ()
4. $. ajax ()
----------------------------------Test.html -------------------------
<Body>
<Ul id = "test1">
<Li> 11111 </li>
<Li> 22222 </li>
<Li> 33333 </li>
</Ul>
<Ul id = "test2">
<Li> aaaaa </li>
<Li> cccccc </li>
<Li> ddddd </li>
</Ul>
</Body>
----------------------------- Demo1 --------------------------------
<! 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" xml: lang = "en">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> demo1 </title>
<Style>
. Load {width: 500px; height: 300px; border: 1px solid # abcdef ;}
</Style>
<Script src = "jquery. js"> </script>
</Head>
<Body>
<Input type = "button" value = "LOAD"/>
<Div class = "load"> </div>
<Script>
$ ('Input [type = button] '). click (function (){
Certificate ('.load').load('test.html? Date = '+ Math. random () +' # test2 ');
});
</Script>
/* <Script>
$ ('Input [type = button] '). click (function (){
Pai.get('test.txt? Data = '+ Math. random (), function (data ){
Certificate ('.load').html (data );
});
});
</Script> */
</Body>
</Html>
--------------------------------------------------------------------------------
<! 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" xml: lang = "en">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> demo </title>
<Script src = "jquery. js"> </script>
<Style>
Div {color: red ;}
</Style>
</Head>
<Body>
<Input type = "text" name = "username" id = "username"/>
<Input type = "button" value = "test"/>
<Div> </div>
<Script>
$ ('Input [type = button] '). click (function (){
// The format of the sent parameter must be json.
Var send = {'username': $ ('# username'). val ()}
$ ('Div '). load ('process. php', send, function (data ){
Alert (data );
});
});
</Script>
/* <Script>
$ ('Input [type = button] '). click (function (){
Var url = 'process. php ';
Var sendData = {'username': $ ('# username'). val ()};
$. Get (url, sendData, function (data ){
If (data = 'true '){
Users ('div'0000.html ('user name is usable ');
} Else {
Users ('div'{.html ('user name cannot be admin ');
}
});
})
</Script> */
/* <Script>
$ ('Input [type = button] '). click (function (){
Var url = 'process. php ';
Var sendData = {'username': $ ('# username'). val ()};
$. Ajax ({
Url: url,
Type: 'post ',
Data: sendData,
Success: function (data ){
If (data = 'true '){
Users ('div'0000.html ('user name is usable ');
} Else {
Users ('div'{.html ('user name cannot be admin ');
}
}
});
})
</Script> */
</Body>
</Html>
-------------------------- Process. php ------------------------------
<? Php
Header ('content-type: text/html; chartset = UTF-8 ');
$ Username = $ _ POST ['username'];
// $ Username = $ _ GET ['username'];
If ($ username = 'admin '){
Echo 'false ';
} Else {
Echo "true ";
}
Zookeeper