Javascript examples for jQuery Method and Property:get
The $.get() method loads data from the server using a HTTP GET request.
$.get(URL,data,function(data,status,xhr),dataType)
Parameter | Require | Description |
---|---|---|
URL | Required. | URL to request |
data | Optional. | data to send to the server along with the request |
function(data,status,xhr) | Optional. | a function to run if the request succeeds |
dataType | Optional. | data type of the server response. By default jQuery would do the guess. |
function(data,status,xhr) parameters:
Possible types for dataType:
Request "test.php" and send some additional data along with the request (ignore return results):
$.get("test.php", { name:"Mary", town:"England" });
Request "test.php" and pass arrays of data to the server (ignore return results):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Request "test.php" and alert the result of the request:
$.get("test.php", function(data){ console.log("Data: " + data); });
The following code shows how to request "test.php", but ignore return results:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $.get("test.php"); });/* w w w . j a v a 2s. com*/ }); </script> </head> <body> <button>test</button> </body> </html>