JQuery post () event usage

Source: Internet
Author: User

JQuery. post () is a data submission method in jquery ajax. I will introduce jQuery in detail below. post () usage and some details. I hope this method will be helpful to you.

Load data through http post requests on the server

Version added: 1.0jQuery.post (url, [data], [success (data, textStatus, jqXHR)], [dataType])
The url contains the URL string for sending the request.

The object or string parameter that data sends to the server.

Success (data, textStatus, jqXHR) callback function executed after the request is successful.

The expected data type returned by dataType from the server. Default Value: Smart prediction (xml, json, script, or html ).

This is a fast AJax processing function, equivalent:

The Code is as follows: Copy code

$. Ajax ({
Type: 'post ',
Url: url,
Data: data,
Success: success
DataType: dataType
});

The callback function of success includes the XML root node, String, JavaScript file, or JSON object according to the response of the MIME type ,. It also passes the response text status.

In jQuery 1.5, the success callback function also passes the "jqXHR" Object (in jQuery 1.4, it uses the XMLHttpRequest object ).

Most implementations will specify a successful processing function:

The Code is as follows: Copy code

$. Post ('ajax/test.html ', function (data ){
Certificate ('.result').html (data );
});

All the HTML code snippets requested in this example are inserted into the page.

Pages obtained using POST are never cached, so the cache and ifModified options in these requests are ineffective in jQuery. ajaxSetup.


This function is short for the following functions

The Code is as follows: Copy code
$. Ajax ({
Type: 'post ',
Url: url,
Data: data,
Success: success,
DataType: dataType
});

Example:

The Code is as follows: Copy code

$. Post ("test. php", {"func": "getNameAndTime "},
Function (data ){
Console. log (data. name); // John
Console. log (data. time); // 2
}, "Json ")
. Success (function () {alert ("second success ");})
. Error (function () {alert ("error ");})
. Complete (function () {alert ("complete ");});

Detailed description of dataType Parameters

Data type to be returned from the server. if this parameter is not specified, jQuery will generate XML based on the MIME type of the returned results (xml mime type will generate XML, in 1.4 JSON will generate a JavaScript Object, and in 1.4 script will execute the script, and others will be returned as strings) Try to deduce it. the available types (and the final result of the first parameter passed to the success callback function) are:

"Xml": returns an XML document that can be parsed using jQuery.

"Html": returns HTML as normal text; encoded ded script tags are evaluated when inserted in the DOM.

"Script": treats the returned value as JavaScript and returns it in plain text. disables caching by appending a query string parameter, "_ = [TIMESTAMP]", to the URL unless the cache option is set to true. note: This will turn POSTs into GETs for remote-domain requests.

"Json": treats the returned value as JSON and returns a JavaScript Object. in jQuery 1.4 JSON data is parsed In a strict manner. JSON with any format exception is rejected and a parse error is thrown. (

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.