JQuery Ajax POST Request detailed description and example

Source: Internet
Author: User
Tags http post php code php tutorial

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.

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.