Home >Web Front-end >JS Tutorial >The use of ajax post in jquery
jQuery.post(url, [data], [callback], [type])
Overview
Load information via remote HTTP POST request.
This is a simple POST request function to replace the complex $.ajax. The callback function can be called when the request is successful. If you need to execute a function on error, use $.ajax.
Parameters
url,[data],[callback],[type]String,Map,Function,StringV1.0
url: Send request address.
data: Key/value parameters to be sent.
callback: callback function when sending successfully.
type: Return content format, xml, html, script, json, text, _default.
Example
1) Pass an array of data to the server (while still ignoring the return value):
jQuery code:
$.post("test.php", { 'choices[]': ["Jon", "Susan"] });
2) Send form data using ajax request:
jQuery code:
$.post("test.php", $("#testform").serialize());
3) Test the page .php sends data and outputs the result (HTML or XML, depending on the returned content):
jQuery code:
$.post("test.php", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); });
4) Get the content of the test.php page and store it as an XMLHttpResponse object and pass it through process() This JavaScript function is processed:
jQuery code:
$.post("test.php", { name: "John", time: "2pm" }, function(data){ process(data); }, "xml");
5) Get the json format content returned by the test.php page:
jQuery code:
$.post("test.php", { "func": "getNameAndTime" }, function(data){ alert(data.name); // John console.log(data.time); // 2pm }, "json");