Home > Article > Web Front-end > What are the parameters of jquery post method?
The parameters of the jquery post method are: 1. URL, which stipulates which URL the request will be sent to; 2. data, which stipulates the data sent to the server along with the request; 3. function(), which stipulates that it will be run when the request is successful. function; 4. dataType, specifies the data type of the expected server response.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The post() method loads data from the server using an HTTP POST request.
Syntax:
$(selector).post(URL,data,function(data,status,xhr),dataType)
post() method supports 4 parameters:
Parameter | Description |
---|---|
URL | Required. Specifies the URL to which requests are sent. |
data | Optional. Specifies the data to be sent to the server with the request. |
function(data,status,xhr) |
Optional. Specifies a function to run when the request succeeds. Additional parameters:
|
dataType |
Optional. Specifies the data type of the expected server response. By default, jQuery will figure it out intelligently. Possible types:
|
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $.post("/try/ajax/demo_test_post.php",{ name:"PHP中文网", url:"https://www.php.cn/" }, function(data,status){ alert("数据: \n" + data + "\n状态: " + status); }); }); }); </script> </head> <body> <button>发送一个 HTTP POST 请求页面并获取返回内容</button> </body> </html>
Run, After clicking the button, a pop-up display appears:
Recommended related video tutorials: jQuery Tutorial (Video)
The above is the detailed content of What are the parameters of jquery post method?. For more information, please follow other related articles on the PHP Chinese website!