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 );}
});