JQuery uses ajax post and get to send data

Source: Internet
Author: User

JQuery is a very powerful class library. I learned about it today and fell in love with it. Let's talk about how to use ajax in jQuery.

Example:

Test.html

Page reference <script type = "text/javascript" src = "jquery-1.3.2.min.js"> </script>

Content:

<Div id = "divMsg"> Hello World! </Div>

Usage 1: (the remote page content is read to divMsg when the page is loaded)

 

$ ("# DivMsg"). load (http: // localhost: 8012/t. asp, {"resultType": "html "});

The returned type resultType is as follows:

"Xml", "html", "script", "json", "jsonp", "text"

Usage 2: (Click post to return data)

<Input type = "button" id = "bnajax" value = "ajax" onclick = "ajaxTest ()"/>

<Script type = "text/javascript">

Function ajaxTest ()
{
$. Post ("http: // localhost: 8012/t. asp", {"txt": "123"}, function (data)
{
$ ("# DivMsg" pai.html (data );
}
);
}

</Script>

 

The following are functions taken from the network:

The post method is as follows:

Function test (access_url, tipE ){

$. Post (access_url ,{
First: "test1", second: "test2"
}, Function (data ){
If (data. success ){
$ ('#' + TipE).html ('processed successfully ');
} Else {
$ ('#' + TipE).html (data. msg );
}
}, 'Json'
)
}

 

If you want to use the get method, you can replace post with get, which is quite simple!

The data value in this function is the value returned by the server in JSON format. Of course, other types such as text and xml can be used here.

The return value on the server is in JSON format, for example, {success: true, msg: "tested "}

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.