A simple example of get and post in jquery _jquery

Source: Internet
Author: User

Example:

Test.html
Page reference <script type= "Text/javascript" src= "Jquery-1.3.2.min.js" ></script>

The contents are:
<div id= "divmsg" >hello world!</div>

Usage 1: (Read the remote page content on page load to divmsg)

$ ("#divMsg"). Load (http://localhost:8012/t.php, {"Resulttype": "html"});

The return type Resulttype has the following kinds:

"XML", "HTML", "script", "JSON", "Jsonp", "text"

Usage 2: (click Post data to return data)

Copy Code code as follows:

<input type= "button" id= "Bnajax" value= "Ajax" onclick= "Ajaxtest ()"/>
<script type= "Text/javascript" >
function Ajaxtest ()
{
$.post ("http://localhost:8012/t.php", {"TXT": "123"},function (data)

{
$ ("#divMsg"). HTML (data);
}
);
}
</script>


The following are the functions that are excerpted from the network:

The Post method is as follows:

Copy Code code as follows:

function test (Access_url, tipe) {

$.post (access_url,{
A: "Test1", Second: "Test2"
}, function (data) {
if (data.success) {
$ (' # ' + tipe). HTML (' process success ');
}else{
$ (' # ' + tipe). HTML (DATA.MSG);
}
}, ' JSON '
)
}


If you want to use the Get method, then put the post for get is OK, quite simple!

The data value in this function is the value returned by the server and is in JSON format, and of course, there are other types, such as Text,xml and so on.

The service-side return value is in JSON format, such as: {success:true, msg: "Test succeeded"}

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.