Método jQuery get()

❮ Métodos jQuery AJAX

Exemplo

Envie uma solicitação HTTP GET para uma página e receba um resultado de volta:

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

Definição e uso

O método $.get() carrega dados do servidor usando uma solicitação HTTP GET.


Exemplos

Solicite "test.php", mas ignore os resultados de retorno:

$.get("test.php");

Solicite "test.php" e envie alguns dados adicionais junto com a solicitação (ignore os resultados de retorno):

$.get("test.php", { name:"Donald", town:"Ducktown" });

Solicite "test.php" e passe arrays de dados para o servidor (ignore os resultados de retorno):

$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });

Solicite "test.php" e alerte o resultado da solicitação:

$.get("test.php", function(data){
  alert("Data: " + data);
});


Sintaxe

$.get(URL,data,function(data,status,xhr),dataType)

Parameter Description
URL Required. Specifies the URL you wish to request
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

❮ Métodos jQuery AJAX