发送异步http GET请求以从服务器加载数据。其一般形式是:
jQuery.get( url [, data ] [, success ] [, dataType ] )
url
:唯一的必需参数。该字符串包含发送请求的地址。如果未指定其他参数,则将忽略返回的数据。data
:带有请求发送到服务器的普通对象或字符串。success
:如果请求成功,则执行回调函数。它将返回的数据作为参数。它还传递了响应的文本状态。dataType
:服务器所需的数据类型。默认为Intelligent Guess(xml,json,script,text,html)。如果提供此参数,则还必须提供成功回调。
例子
Request resource.json
from the server, send additional data, and ignore the returned result:
$.get('http://example.com/resource.json', {category:'client', type:'premium'});
Request resource.json
from the server, send additional data, and handle the returned response (json format):
$.get('http://example.com/resource.json', {category:'client', type:'premium'}, function(response) {
alert("success");
$("#mypar").html(response.amount);
});
The above example can also be written as:
$.get('http://example.com/resource.json', {category:'client', type:'premium'})
.done(function(response) {
alert("success");
$("#mypar").html(response.amount);
});
jQuery.ajax()
$.get( url [, data ] [, success ] [, dataType ] )
is a shorthand Ajax function, equivalent to:
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
更多jQuery教程
学习更多jQuery教程