Home > Article > Web Front-end > jquery get can have several parameters
get() can have 4 parameters: 1. The first parameter cannot be omitted and is used to specify the URL that needs to be requested; 2. The second parameter can be omitted and is used to specify the URL that is sent to the server along with the request. Data; 3. The third parameter can be omitted, specifying the callback function to be run when the request is successful; 4. The fourth parameter can be omitted, specifying the data type of the expected server response.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The jQuery get() method loads data from the server using an HTTP GET request.
The get() method accepts 4 parameters (one required, three optional)
$.get(URL,data,function(data,status,xhr),dataType)
Parameters | Description |
---|---|
URL | Required. Specifies the URL you need to request. |
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:
|
Request "test.php", but ignore the return result:
$.get("test.php");
Request "test.php" and send some additional data along with the request (ignore the return result):
$.get("test.php", { name:"Donald", town:"Ducktown" });
Request "test.php" and pass the data array to the server (ignore the return result):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Request "test.php" and remind the result of the request:
$.get("test.php", function(data){ alert("Data: " + data); });
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() { $.get("/try/ajax/demo_test.php", function(data, status) { alert("数据: " + data + "\n状态: " + status); }); }); }); </script> </head> <body> <button>发送一个 HTTP GET 请求并获取返回结果</button> </body> </html>
【Recommended Learning :jQuery video tutorial、web front-end video】
The above is the detailed content of jquery get can have several parameters. For more information, please follow other related articles on the PHP Chinese website!