Latest web development tutorials

jQuery get () method

jQuery AJAX Methods jQuery AJAX Methods

Examples

Send an HTTP GET request to the page and get back the results:

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

try it"

Definition and Usage

$ .get () Method uses the HTTP GET request to load data from the server.


Examples

Request "test.php", but ignore the return result:

$.get("test.php");

Request "test.php" and send some additional data (ignoring the return results) together with the request:

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

Request "test.php" and pass an array of data to the server (ignore the return results):

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

Request "test.php" and reminded result of the request:

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


grammar

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

参数 描述
URL 必需。规定您需要请求的 URL。
data 可选。规定连同请求发送到服务器的数据。
function(data,status,xhr) 可选。规定当请求成功时运行的函数。
额外的参数:
  • data - 包含来自请求的结果数据
  • status - 包含请求的状态("success"、"notmodified"、"error"、"timeout"、"parsererror")
  • xhr - 包含 XMLHttpRequest 对象
dataType 可选。规定预期的服务器响应的数据类型。
默认地,jQuery 会智能判断。
可能的类型:
  • "xml" - 一个 XML 文档
  • "html" - HTML 作为纯文本
  • "text" - 纯文本字符串
  • "script" - 以 JavaScript 运行响应,并以纯文本返回
  • "json" - 以 JSON 运行响应,并以 JavaScript 对象返回
  • "jsonp" - 使用 JSONP 加载一个 JSON 块,将添加一个 "?callback=?" 到 URL 来规定回调


jQuery AJAX Methods jQuery AJAX Methods