jQuery post() Metodo

❮ Metodi jQuery AJAX

Esempio 1

Carica i dati dal server utilizzando una richiesta HTTP POST:

$("button").click(function(){
  $.post("demo_test.asp", function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
  });
});

Esempio 2

Modifica il testo di un elemento <div> utilizzando una richiesta AJAX POST:

$("input").keyup(function(){
  var txt = $("input").val();
  $.post("demo_ajax_gethint.asp", {suggest: txt}, function(result){
    $("span").html(result);
  });
});

Definizione e utilizzo

Il metodo $.post() carica i dati dal server utilizzando una richiesta HTTP POST.



Sintassi

$(selector).post(URL,data,function(data,status,xhr),dataType)

Parameter Description
URL Required. Specifies the url to send the request to
data Optional. Specifies data to send to the server along with the request
function(data,status,xhr) Optional. Specifies a 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. Specifies the data type expected of the server response.
By default jQuery performs an automatic guess.
Possible types:
  • "xml" - An XML document
  • "html" - HTML as plain text
  • "text" - A plain text string
  • "script" - Runs the response as JavaScript, and returns it as plain text
  • "json" - Runs the response as JSON, and returns a JavaScript object
  • "jsonp" - Loads in a JSON block using JSONP. Will add an "?callback=?" to the URL to specify the callback

❮ Metodi jQuery AJAX