Jquery.post (URL, [data], [callback], [type])
Load information through a remote HTTP POST request and use Post to make asynchronous requests.
This is a simple POST request function to replace the complex $.ajax. Callback functions can be invoked when the request succeeds. If you need to perform a function when an error occurs, use $.ajax.
return value: XMLHttpRequest
Parameters:
URL (string): The URL address where the request is sent.
Data (map): (optional) The information to be sent to the server, expressed as a Key/value key-value pair.
Callback (function): (optional) the callback function (which is invoked only if the response return state is success) when loading succeeds.
Type: (string): (optional) The official description is: type of data to is sent. The type that should actually be requested for the client (Json,xml, etc.)
Example:
ajax.asp Tutorial x:
Program code
Response.ContentType = "Application/json";
Response.Write ("{result: '" + request["name"] + ", Hello! (This message comes from the server) '} ');
Jquery
Code:
Program code
$.post ("Ajax.aspx", {action: "POST", Name: "Lulu"},
function (data, textstatus) {
Data can be xmldoc, jsonobj, HTML, text, and so on.
This This AJAX request option configuration information, please refer to Jquery.get ().
alert (Data.result);
}, "JSON");
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<script language= "Web Effects" src= "Jquery-1.4.2.min.js" ></script>
<script language= "JavaScript" >
$ (function () {//<!--www.111cn.net jquery code Area-->
Ajax Code Area
});
</script>
<body>
<input id= "forasp" type= "text" maxlength= "M" > <input type= "button" value= "Ajax test for jquery" Id= "cn" >
<span id= "Backurl" >www.forasp.cn</span>
</body>
As mentioned earlier, using $.ajax (options) to implement the Jqueryajax, where the submission is set in type, this time the Ajax is directly marked with the Post method to submit data.
(1) Grammar: $.get (Url,data,fun,type);
URLs represent pages of Ajax calls
Date is the data passed by the Get method, data format {Data:value,data:value.} Optional
Fun is a callback function, function (msg), and MSG is the page return content. Optional
Type returns the content format, XML, HTML, script, JSON, text, _default. Optional
Instance:
$ ("#cn"). Bind ("click", Function () {
$.post ("index4.php tutorial", {foraspcnurl:$ ("#forasp"). Val ()},function (msg) {alert (msg);});
});
The call page in the example is index4.php code as follows: <?echo $_post["Foraspcnurl"];? ".
Run: When the text inside the input web site production Learning Network, click the Back button, pop-up "Web Site Production Learning Network" dialog box
This direct post method has no functions such as beforsend,error, use $.ajax if you need to perform functions when an error occurs.