Javascript examples for jQuery Method and Property:post
The $.post() method loads data from the server using a HTTP POST request.
$(selector).post(URL, data, function(data,status,xhr), dataType);
Parameter | Require | Description |
---|---|---|
URL | Required. | url to send the request to |
data | Optional. | data to send to the server along with the request |
function(data,status,xhr) | Optional. | function to run if the request succeeds Additional parameters: data - contains the resulting data from the request status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror") xhr - contains the XMLHttpRequest object |
dataType | Optional. | data type of the server response. |
Possible data types:
The following code shows how to load data from the server using a HTTP POST request:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").keyup(function(){ var txt = $("input").val(); $.post("demo.asp", {suggest: txt}, function(result){ $("span").html(result); });/* w w w . j av a 2 s . c o m*/ }); }); </script> </head> <body> First name: <input type="text"> <p>Suggestions: <span></span></p> </body> </html>