JQuery learning lesson 8 (ajax in jquery)

Source: Internet
Author: User

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

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.