Jquery.post Method and Example tutorial

Source: Internet
Author: User

Jquery.post (URL, [data], [Success (data, Textstatus, XMLHttpRequest)], [datatype])

Returns:xmlhttprequest


Jquery.post (URL, [data], [Success (data, Textstatus, XMLHttpRequest)], [datatype])
The Ulla string that contains the URL of the request is sent.

Dataa a map or string of requests sent to the server.
Success (data, Textstatus, XMLHttpRequest) A callback function this is executed if the request succeeds.

Datatypethe type of data expected from the server.

This is a shorthand Ajax function and which is equivalent to:

$.ajax ({
Type: ' Post ',
Url:url,
Data:data,
Success:success
Datatype:datatype
});


This success is the data returned by the callback function, which will be an XML root element or a text string based on the MIME type of the response. It also passed the status of the response text.

In jquery 1.4, the successful callback function is also passed through the XMLHttpRequest object.

Most implementations will specify a successful handler:

$.post (' ajax/test.html ', function (data) {
$ ('. Result '). HTML (data);
});


Examples:
For example: Please test.php the tutorial page, but ignore the return result.

$.post ("test.php");

Example

Request the test.php page and send some additional data along (while still ignoring the return results).
Request a test.php Web page, sending some extra data along (while still ignoring the return result).
$.post ("test.php", {name: "John", Time: "2pm"});

Example:pass arrays of data to the server (while still ignoring the return results).
$.post ("test.php", {' choices[] ': ["Jon", "Susan"]});

Example:send form data using AJAX requests
$.post ("test.php", $ ("#testform"). Serialize ());

Example:alert out of the results from requesting test.php (HTML or XML, depending on what is returned).
$.post ("test.php", function (data) {
Alert ("Data loaded:" + data);
})

; Example:alert out the results from requesting test.php with a additional payload of data (HTML or XML, depending on WHA T was returned).
$.post ("test.php", {name: "John", Time: "2pm"},
function (data) {
Alert ("Data loaded:" + data);
Example:gets the test.php page content, store it in a Xmlhttpresponse object and applies the process () Web effects function.
$.post ("test.php", {name: "John", Time: "2pm"},
function (data) {
Process (data);
}, "xml");


Example:gets the test.php page contents which has been in JSON format ()
$.post ("test.php", {"Func": "Getnameandtime"},
function (data) {
alert (data.name); John
Console.log (Data.time); 2pm
}, "JSON");

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.