Javascript jquery $. Post $. Ajax usage

Source: Internet
Author: User

Jquery. Post (URL, [data], [callback], [type]): Use the POST method for asynchronous requests.

Parameters:

URL (string): the URL of the request.

Data (MAP): (optional) data to be sent to the server, expressed in key/value pairs.

Callback (function): (optional) callback function when the load is successful (this method is called only when the response returns success ).

Type (string): (optional) the official description is: type of data to be sent. In fact, it should be the client request type (JSON, XML, and so on)

This is a simple POST Request function to replace complex $. Ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. Ajax. ExampleCode:

Ajax. aspx:

Response. contenttype = "application/JSON"; response. Write ("{result: '" + request ["name"] + ", hello! (This message comes from the server) '} "); jquery code:
$. Post ("Ajax. aspx ", {Action:" Post ", name:" Lulu "}, function (data, textstatus) {// data can be xmldoc, jsonobj, HTML, text, and so on. // This; // configure the options for this Ajax request. For more information, see jquery. this alert (data. result) ;}, "JSON"); click submit:

The request format is set to "JSON ":

$. Ajax () is the underlying Ajax Implementation of jquery. For easy-to-use high-level implementation, see $. Get, $. Post, and so on.

There are several Ajax event parameters: beforesend, success, complete, and error. We can define these events to process every Ajax request.

$. Ajax ({URL: 'stat. php ',

Type: 'post ',

Data: {name: "keyun "},

Datatype: 'html ',

Timeout: 1000,

Error: function () {alert ('error loading PHP document ');},

Success: function (result) {alert (result );}

});

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.