instance Request test.php Web page, ignoring return value: $.post ("Test.php"); Tiy instance changes the text of the DIV element via an AJAX POST request: $ ("Input"). KeyUp (function() {txt=$ ("Input"). Val (); $.post ("Demo_ajax_gethint.asp", {suggest:txt},function(Result) {$ ("Span"). HTML (result); });}); Try it yourself. Define and use the post () method to load data from the server via an HTTP POST request. Syntax Jquery.post (url,data,success (data, Textstatus, JQXHR), dataType) parameter description URL required. Specifies which URL to send the request to. Data is optional. The map or string value. Specifies the data that is sent to the server along with the request. Success (data, Textstatus, JQXHR) is optional. The callback function to execute when the request succeeds. DataType is optional. Specifies the data type of the expected server response. The default is to perform smart judgments (XML, JSON, script, or HTML). The function is abbreviated Ajax function, equivalent to: $.ajax ({type:' POST ', Url:url, Data:data, success:success, datatype:datatype}); The return data passed to the success callback function differs depending on the MIME type of the response, which can be an XML root element, a text string, a JavaScript file, or a JSON object. You can also pass the text state of the response to the success callback function. For JQuery1.5, you can also pass JQXHR objects to the success callback function (JQuery 1.4The XMLHttpRequest object is passed in. Most implementations will prescribe a success function: $.post ("Ajax/test.html",function(data) {$ (". Result"). HTML (data);}); This example reads the requested HTML fragment and inserts it into the page. Pages that are read through POST are not cached, so the cache and ifmodified options in Jquery.ajaxsetup () do not affect these requests. Note: Due to browser security limitations, most"Ajax"request compliance with the same-origin policy; The request cannot retrieve data successfully from a different domain, subdomain, or protocol. Note: If a request initiated by Jquery.post () returns an error code, there is no hint unless the script has called the Global. Ajaxerror () method. or for JQuery .1.5, the. Error () method of the Jqxhr object returned by Jquery.post () can also be used for error handling. JQXHR Objects for JQuery1.5, all JQuery's AJAX methods return a superset of the XMLHttpRequest object. The JQuery XHR object returned by $.post () or "jqxhr,"implements the agreed interface, giving it all its properties, methods, and the behavior of the contract. Given the convenience and consistency of the callback function name used by $.ajax (), it provides the. Error (),. Success (), and. Complete () methods. These methods use the function arguments that are called when the request terminates, and the function accepts the same parameters as the corresponding named $.ajax () callback function. JQuery1.5the contract interface in the same way allows JQuery's Ajax methods, including $.post (), to link multiple. Success (),. complete (), and. Error () callback functions for the same request, even after the request may have completed. //assign a handler immediately after the request is generated, keeping in mind that the request is for the JQXHR object varJQXHR = $.post ("example.php",function() {alert ("Success"); }). Success (function() {alert ("second Success"); }). Error (function() {Alert ("error")); }). Complete (function() {Alert ("complete"); }); //perform other tasks here //set another completion function for the above requestJqxhr.complete (function() {alert ("second complete"); }); more example Examples1request the test.php page and send some extra data together (while still ignoring the return value): $.post ("Test.php", {name: "John", Time: "2pm"}); example2passing an array of data to the server (while still ignoring the return value): $.post ("Test.php", {' choices[] ': ["Jon", "Susan"]}); example3send form data using AJAX requests: $.post ("Test.php", $ ("#testform"). Serialize ()); example4outputs the results from the requested page test.php (HTML or XML, depending on what is returned): $.post ("Test.php",function(data) {alert ("Data Loaded:" +data); }); example5sends the data to the page test.php and outputs the result (HTML or XML, depending on what is returned): $.post ("Test.php", {name: "John", Time: "2pm" }, function(data) {alert ("Data Loaded:" +data); }); example6get the contents of the test.php page and store it as a Xmlhttpresponse object and process it through the JavaScript function of process (): $.post ("Test.php", {name: "John", Time: "2pm" }, function(data) {process (data); }, "XML"); example7get the contents of the JSON format returned by the test.php page: $.post ("Test.php", {"Func": "Getnameandtime" }, function(data) {alert (data.name);//JohnConsole.log (Data.time);//2pm}, "JSON");
JQuery Ajax-post () method