jQuery - AJAX

创建时间:
2015-06-04 20:55
最近更新:
2018-09-30 23:05

Documentation

Jquery Ajax API 共 18 项

请求 6 种

  1. $.ajax()
  2. $.get()
  3. $.post()
  4. $.getScript()
  5. $.getJSON()
  6. .load()

jQuery 对 AJAX 操作进行了封装,
最底层是:
$.ajax()
第二层是:
$.get()
$.post()
laod()
第三层是:
$.getScript()
$.getJSON()

全局事件 6 种

jQuery 有两种 AJAX 事件: 局部事件 和 全局事件

  1. .ajaxComplete()
  2. .ajaxError()
  3. .ajaxSend()
  4. .ajaxStart()
  5. .ajaxStop()
  6. .ajaxSuccess()

序列化 3 种

  1. .serialize()
  2. .serializeArray()
  3. $.param()

设置 3 种

  1. $.ajaxPrefilter()
  2. $.ajaxSetup()
  3. $.ajaxTransport()

Resource - 统一 异常/错误 处理

  1. 使用重写的 $.ajax() 统一错误处理
  2. 统一处理 jQuery AJAX 请求过程中的异常错误信息的机制 - 文摘: "最后,将对异常的处理代码作为公共资源引入各个页面,实现统一展现、处理异常的功能,使用 jQuery 的 ajaxError 事件"、"对于非 AJAX 请求异常,直接交给 web.xml 来处理"
  3. jQuery - 拦截所有 AJAX 请求 (统一处理超时、返回结果、错误状态码)

测试记录 - 对比测试 jQuery 与原生的 XmlHttpRequest

详见 D1526Bakup/CodeAccumulation/Script/Ajax/对比测试:jQuery与原生的XmlHttpRequest

测试记录 - 完整的关于 "C# Response.StatusCode and Response.StatusDescription" 的测试

详见 D1526Bakup/CodeAccumulation/Script/Ajax/测试jQueryAjax的settings.htm

测试记录 - $.ajax()Response.Redirect(url) 导致的 302

jQuery 通过 $.ajax() 请求 http://localhost/CommerceSg/A/Mngr/Login.aspx,
ASP.NET 收到请求后立即 Response.Redirect("http://localhost/CommerceSg/Contact.aspx"),
导致该请求的响应标头中有: HTTP/1.1 302 Found、Location=http://localhost/CommerceSg/Contact.aspx、无响应正文、无 cookie。

IE 收到此响应,随即使用 jQuery 的 $.ajax() 请求 http://localhost/CommerceSg/Contact.aspx,此次请求标头中有:GET /CommerceSg/Contact.aspx HTTP/1.1、IsAjaxRequest=true、Referer=http://localhost/CommerceSg/A/Mngr/Login.aspx、无请求正文。
ASP.NET 收到请求并响应,响应标头中有: HTTP/1.1 200 OK,响应正文为 http://localhost/CommerceSg/Contact.aspx 的 HTML,有 key=ASP.NET_SessionId 的会话 cookie。

至此,Redirect 导致的 2 次往返结束。

结论:
jQuery 的 $.ajax() 仍遵守 302 约定,会自动请求 302 目标页。
如需使用返回的 302 目标页,必须为此特别编码。

测试记录 - jQuery 事件处理程序中 this 为 DOM 元素,原因不详

jBtn.click(function () {
    $.ajax({
        Btn: this, //因为 this 为 DOM 元素,
        url: "xxx",
        success: function (data) {
            $(this.Btn).val(data); //所以 this.Btn 必须用 $() 包装。
        }
    });
});

以下为文档

jQuery.ajax()

http://api.jquery.com/jQuery.ajax/ - 参数 settings 详见本站专文

Returns: jqXHR
Description: Perform an asynchronous HTTP (Ajax) request.

Syntax:

  • jQuery.ajax(url[,settings]) version added: 1.5
  • jQuery.ajax([settings]) version added: 1.0

load、get、post、getScript、getJSON 均为此方法的封装。
当设置 datatype 为 script 的时候,所有的远程 (不在同一个域中) post 请求都会转换为 get 方式。
beforeSend、success、complete、error 回调函数里面的 this,指向的是 AJAX 请求的选项配置信息。

jqXHR 对象

$.ajax() 返回的 jqXHR 对象是浏览器原生 XMLHttpRequest 对象的超集,并尽可能地模仿原生对象的功能.

为向后兼容 XMLHttpRequestjqXHR 对象将公开以下属性和方法 (Tony已排序) (Tony 测试过 2 者的成员,详见 D:\CodeAccumulation\Script\Ajax\中的测试文档):

  1. abort([statusText])
  2. getAllResponseHeaders() as a string
  3. getResponseHeader(name)
  4. readyState
  5. responseXML and/or responseText when the underlying request responded with xml and/or text, respectively
  6. setRequestHeader(name, value) which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one
  7. status
  8. statusText
  9. overrideMimeType(mimeType)
  10. statusCode(callbacksByStatusCode)

TonyRemark:
C# 中设置 Response.StatusCode 为任意整数 (即使是不存在的 HTTP 状态码),$.ajax() 各回调函数中的 jqXHR.status 均能收到。

没有 onreadystatechange 的机制被提供,因为 successerrorcompletestatusCode 覆盖了所有可能的需求。

Example

//设置 AJAX 请求默认地址为 "/xmlhttp/"、禁止触发全局 AJAX 事件、用 POST 代替默认 GET 方法:
$.ajaxSetup({
    url: "/xmlhttp/",
    global: false,
    type: "post"
});
$.ajax({data: myData}); //其后的 AJAX 请求无需再设置任何选项参数。

jQuery.ajaxSetup()

http://api.jquery.com/jQuery.ajaxSetup/

jQuery.getJSON()

http://api.jquery.com/jQuery.getJSON/
http://www.jquery123.com/jQuery.getJSON/

2013-07-29 Tony 测试记录:$.getJSON()总是GET,即使$.ajaxSetup({type:"POST"})也无法改变此行为。Tony未发现$.getJSON()有暴露设置为POST的API。因此Tony再次觉得统一使用$.ajax()的习惯是正确的。

version added: 1.0
Returns: jqXHR
Description: Load JSON-encoded data from the server using a GET HTTP request.

Syntax: var jqXHR = jQuery.getJSON( url [, data ] [, success(data,textStatus,jqXHR) ] );
url, Type: String, A string containing the URL to which the request is sent.
data, Type: PlainObject or String, A plain object or string that is sent to the server with the request.
success, Type: Function( PlainObject data, String textStatus, jqXHR jqXHR ), A callback function that is executed if the request succeeds.

Data that is sent to the server is appended to the URL as a query string. If the value of the data parameter is a plain object, it is converted to a string and url-encoded before it is appended to the URL.

This is a shorthand Ajax function, which is equivalent to:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback
});

Most implementations will specify a success handler:

$.getJSON('ajax/test.json', function(data){
    var items = [];
    $.each(data, function(key, val){
        items.push('<li id="' + key + '">' + val + '</li>');
    });
    $('<ul/>', {
        'class':'my-new-list',
        html:items.join('')
    }).appendTo('body');
});

This example, of course, relies on the structure of the JSON file:

{
    "one": "Singular sensation",
    "two": "Beady little eyes",
    "three": "Little birds pitch by my doorstep"
}

Using this structure, the example loops through the requested data, builds an unordered list, and appends it to the body.

The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the $.parseJSON() method. It is also passed the text status of the response.

As of jQuery 1.5, the success callback function receives a "jqXHR" object (in jQuery 1.4, it received the XMLHttpRequest object). However, since JSONP and cross-domain GET requests do not use XHR, in those cases the jqXHR and textStatus parameters passed to the success callback are undefined.

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/.

JSONP:

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

The jqXHR Object:(同get/post)
Additional Notes:(同get/post)

Example: Loads the four most recent cat pictures from the Flickr JSONP API.

<div id="images"></div>
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", {
    tags:"cat",
    tagmode:"any",
    format:"json"
}, function(data){
    $.each(data.items, function(i, item){
        $("<img/>").attr("src", item.media.m).appendTo("#images");
        if(i == 3) return false;
    });
});

Example: Load the JSON data from test.js and access a name from the returned JSON data.

$.getJSON("test.js",function(json){alert("JSON Data:"+json.users[3].name);});

Example: Load the JSON data from test.js, passing along additional data, and access a name from the returned JSON data.

$.getJSON("test.js",{name:"John",time:"2pm"},function(json){alert("JSON Data:"+json.users[3].name);});

jQuery.getScript()

http://api.jquery.com/jQuery.getScript/

version added: 1.0
Returns: jqXHR
Description: Load a JavaScript file from the server using a GET HTTP request, then execute it.

var jqXHR = jQuery.getScript( url [, success(script,textStatus,jqXHR) ] );
url: A string containing the URL to which the request is sent.
success(script, textStatus, jqXHR): A callback function that is executed if the request succeeds.

This is a shorthand Ajax function, which is equivalent to:

$.ajax({
    //cache: false, 官方文档无此行
    url: url,
    dataType: 'script',
    success: success
});

P1602 生产代码:

$.ajax({
    async: false,
    cache: true,
    dataType: 'script',
    url: '/Content/js/plugins/echarts/echarts.min.js',
});

jQuery1.2+可以跨域调用JavaScript文件。
Safari2或更早的版本不能在全局作用域中同步执行脚本。如果通过getScript加入脚本,请加入延时函数。

Tony 曾使用以下代码替代 $.getScript():

$.ajax({
    async:false,
    //cache:true,
    dataType:"script",
    type:"GET",
    url:stg.UrlTTreeJs
});

The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page.

Success Callback:
The callback is passed the returned JavaScript file. This is generally not useful as the script will already have run at this point.

$(".result").html("<p>Lorem ipsum dolor sit amet.</p>");

Scripts are included and run by referencing the file name:

$.getScript("ajax/test.js", function(data, textStatus, jqxhr) {
    console.log(data); //data returned
    console.log(textStatus); //success
    console.log(jqxhr.status); //200
    console.log('Load was performed.');
});

Handling Errors:
As of jQuery 1.5, you may use .fail() to account for errors:

$.getScript("ajax/test.js").done(function(script, textStatus) {
    console.log( textStatus );
}).fail(function(jqxhr, settings, exception) {
    $( "div.log" ).text( "Triggered ajaxError handler." );
});

Prior to jQuery 1.5, the global .ajaxError() callback event had to be used in order to handle $.getScript() errors:

$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
    if (settings.dataType=='script') {
        $(this).text( "Triggered ajaxError handler." );
    }
});

Caching Responses:
Be default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():

$.ajaxSetup({cache: true});

Alternatively, you could define a new method that uses the more flexible $.ajax() method.

Example: Define a $.cachedScript() method that allows fetching a cached script:

jQuery.cachedScript = function (url, options) {
    //allow user to set any option except for dataType, cache, and url
    options = $.extend(options || {}, {
        dataType:"script",
        cache:true,
        url:url
    });
    //Use $.ajax() since it is more flexible than $.getScript
    //Return the jqXHR object so we can chain callbacks
    return jQuery.ajax(options);
};
//Usage
$.cachedScript("ajax/test.js").done(function (script, textStatus) {
    console.log(textStatus);
});

Example: Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded.

$(function(){
    $(document.body).html(
        '<input type="button" value="Run"/>' +
        '<div style="background-color:#00f;width:150px;height:70px;margin:10px;"></div>'
    );
    $.getScript("http://api.jquery.com/scripts/jquery.color.js",
        function(){
            $("input[type=button]").click(function(){
                $("div")
                    .animate({backgroundColor:"pink"}, 1000)
                    .delay(500)
                    .animate({backgroundColor:"blue"}, 1000);
            });
        }).fail(function(){
            alert("$.getScript()'s url parameter is not exist.");
        });
});

jQuery.get() & jQuery.post()

http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.post/

Overload:

jQuery.get/post(url[, data][, success(data, textStatus, jqXHR)][, dataType])

jQuery.get ( url [, data ] [, success ] [, dataType ] )
jQuery.post( url [, data ] [, success ] [, dataType ] )
jQuery.get ( [settings ] )
jQuery.post( [settings ] )

version added: 1.0
Returns: jqXHR
Description: Load data from the server using a HTTP GET/POST request.

url: A string containing the URL to which the request is sent.
data: A map or string that is sent to the server with the request.
success(data, textStatus, jqXHR): A callback function that is executed if the request succeeds.

dataType(get): The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
dataType(post): The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).

success 回调函数里面的 this,指向的是 AJAX 请求的选项配置信息。

.get() is a shorthand Ajax function, which is equivalent to:

$.ajax({
    url: url,
    data: data,
    success: success,
    dataType: dataType
});

.post is a shorthand Ajax function, which is equivalent to:

$.ajax({
    type: 'POST',
    url: url,
    data: data,
    success: success,
    dataType: dataType
});

.get()'s success callback function is passed the returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response. It is also passed the text status of the response.

.post()'s success callback function is passed the returned data, which will be an XML root element or a text string depending on the MIME type of the response. It is also passed the text status of the response.

For .get():
As of jQuery 1.5, the success callback function is also passed a "jqXHR" object (in jQuery 1.4, it was passed the XMLHttpRequest object). However, since JSONP and cross-domain GET
requests do not use XHR, in those cases the (j)XHR and textStatus parameters passed to the success callback are undefined.
For .post():
As of jQuery 1.5, the success callback function is also passed a "jqXHR" object (in jQuery 1.4, it was passed the XMLHttpRequest object).

Most implementations will specify a success handler:

$.get/post('ajax/test.html', function(data) {
    $('.result').html(data);
    alert('Load was performed.');
});

This example fetches the requested HTML snippet and inserts it on the page.

Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests.

The jqXHR Object:

As of jQuery 1.5, all of jQuery's Ajax methods return a superset of the XMLHTTPRequest object. This jQuery XHR object, or "jqXHR," returned by $.get/post/getJSON() implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see Deferred object for more information). For convenience and consistency with the callback names used by $.ajax(), it provides .error(), .success(), and .complete() methods. These methods take a function argument that is called when the request terminates, and the function receives the same arguments as the correspondingly-named $.ajax() callback.

The Promise interface in jQuery 1.5 also allows jQuery's Ajax methods, including $.get/post/getJSON(), to chain multiple .success(), .complete(), and .error() callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.

// Assign handlers immediately after making the request, and remember the jqxhr object for this request

var jqxhr = $.get/post/getJSON("example.php/.json",
    function () {
        alert("success");
    }).success(
    function () {
        alert("second success");
    }).error(
    function () {
        alert("error");
    }).complete(function () {
        alert("complete");
    });

// perform other work here ...

// Set another completion function for the request above

jqxhr.complete(function () {
    alert("second complete");
});

Additional Notes:

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
If a request with jQuery.get/post() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method. Alternatively, as of jQuery 1.5, the .error() method of the jqXHR object returned by jQuery.get/post() is also available for error handling.
For .get/getJSON(): Script and JSONP requests are not subject to the same origin policy restrictions.

Example: Request the test.php page, but ignore the return results.

$.get/post("test.php");

Example: Request the test.php page and send some additional data along (while still ignoring the return results).

$.get/post("test.php", { name: "John", time: "2pm" } );

Example: pass arrays of data to the server (while still ignoring the return results).

$.get/post("test.php", { 'choices[]': ["Jon", "Susan"]} );

Example: Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

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

Example: Alert out the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).

$.get/post("test.cgi", { name: "John", time: "2pm" },    function(data){      alert("Data Loaded: " + data);    });

Example: Gets the test.php page contents, which has been returned in json format (<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>), and adds it to the page.

$.get("test.php", function(data){
    $('body')
        .append("Name:" + data.name)//John
        .append("Time:" + data.time);//2pm
}, "json");

Example: Posts to the test.php page and gets contents which has been returned in json format (<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>).

$.post("test.php", {"func":"getNameAndTime"}, function(data){
    console.log(data.name);//John
    console.log(data.time);//2pm
}, "json");

Example: send form data using ajax requests

$.post("test.php", $("#testform").serialize());

Example: Gets the test.php page content, store it in a XMLHttpResponse object and applies the process() JavaScript function.

$.post("test.php",{name:"John",time:"2pm"},function(data){process(data);},"xml");

<form action="/" id="searchForm">
    <input type="text" name="s" placeholder="Search..."/>
    <input type="submit" value="Search"/>
</form>

<div id="result"></div>

$("#searchForm").submit(function(event){
    event.preventDefault();
    var $form = $(this);
    var term = $form.find('input[name="s"]').val();
    var url = $form.attr('action');
    $.post(url, { s:term }, function(data){
        var content = $(data).find('#content');
        $("#result").empty().append(content);
    });
});

Example:

//Ajax.aspx 代码:
Response.ContentType="application/json";//如$.post中设置为"json",而aspx中无此对应设置,则jQuery将无法得到返回的数据。//另一网评:事实上并非完全这样,设置成比如
Response.ContentType="application/text",照样可以得到返回的数据。
Response.Write("{result:'Hello "+Request["Name"]+"From aspx.'}");

//jQuery 代码:
$.post (
    "Ajax.aspx",
    {Name:"Tony"},
    function(data,textStatus){alert(data.result);},//因为下一行设置了JSON格式,故此时返回的data是JSON对象,无需使用eval转换为对象。
    "json"//此处将请求的格式设置为JSON,请求报头中将产生:Accept application/json, text/javascript, */*。
);

.load()

http://api.jquery.com/load/
http://www.jquery123.com/api/load/

var jQueryObject = jQueryObject.load( url [, data ] [, complete(responseText, textStatus, XMLHttpRequest) ] );

描述: 从服务器载入数据并且将返回的 HTML 代码并插入至 匹配的元素 中。
默认使用 GET 方式,如果 data 参数提供一个对象,那么使用 POST 方式。
如果 url 参数的字符串中包含一个或多个空格,那么第一个空格后面的内容,会被当成是 jQuery 的选择器,从而决定应该加载返回结果中的哪部分内容。

version added: 1.0
Returns: jQuery
Description: Load data from the server and place the returned HTML into the matched element.

url: A string containing the URL to which the request is sent.
data: A map or string that is sent to the server with the request.
complete(responseText,textStatus,XMLHttpRequest): A callback function that is executed when the request completes. 尚未找到此回调函数的参数说明。

responseText:
textStatus: "success" or "notmodified" or "error" or 可能还有其它
XMLHttpRequest: xhr.status or xhr.statusText or 可能还有其它

Note these parameters:
Is complete-function not success-function!
Default GET, if data is object(not string), then POST.
URL can like "url selector".

Note: The event handling suite also has a method named .load(). jQuery determines which method to fire based on the set of arguments passed to it.

This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an
implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the
returned data. This means that most uses of the method can be quite simple:
$('#result').load('ajax/test.html');

Callback Function

If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the jQuery collection, and
this is set to each DOM element in turn.

$('#result').load('ajax/test.html', function() {
  alert('Load was performed.');
});

In the two examples above, if the current document does not contain an element with an ID of "result," the .load() method is not executed.

Request Method

The POST method is used if data is provided as an object; otherwise, GET is assumed.

Loading Page Fragments

The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the url parameter.
url参数中如包括1个或多个空白字符,url中第1个空白字符之后的部分被假定为一个jQuery选择符。
If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded.

We could modify the example above to use only part of the document that is fetched:
$('#result').load('ajax/test.html #container');
上述代码执行后,取回了ajax/test.html的内容,jQuery解析返回的文档寻找ID为container的元素。
When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container.
此元素,连同其内容,被插入ID为result的元素,取回的文档的剩余部分被丢弃。
This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

jQuery使用浏览器的innerHTML属性来解析取回的文档,并将其插入当前文档。
jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document.
在这个过程期间,浏览器常常从文档中过滤诸如html, title, head等元素。
During this process, browsers often filter elements from the document such as html, title, or head elements.
结果,通过.load()取回的元素,与直接通过浏览器取回的文档,可能不精确相同。
As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

Script Execution

当使用不带选择器表达式后缀的url参数 调用.load()时,在脚本被删除之前,内容被传递给.html()。
When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed.
脚本在被丢弃前,被执行。
This executes the script blocks before they are discarded.
如使用附加选择器表达式的url参数 调用.load(),然而,在DOM被更新之前脚本被剥离、因此不被执行,
If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed.
An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.
$('#a').load('article.html');

However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:
$('#b').load('article.html #target');

Additional Notes:

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or
protocol.

Example: Load the main page's footer navigation into an ordered list.

$("#new-nav").load("/ #jq-footerNavigation li");

Example: Display a notice if the Ajax request encounters an error.

$("#success").load("/not-here.php", function (response, status, xhr) {
    if (status == "error") {
        var msg = "Sorry but there was an error: ";
        $("#error").html(msg + xhr.status + " " + xhr.statusText);
    }
});

Example: Load the feeds.html file into the div with the ID of feeds.

$("#feeds").load("feeds.html");

Example: pass arrays of data to the server.

$("#objectID").load("test.php", { 'choices[]': ["Jon", "Susan"] } );

Example: Same as above, but will POST the additional parameters to the server and a callback that is executed when the server is finished responding.

$("#feeds").load("feeds.php", {limit: 25}, function(){ alert("The last 25 entries in the feed have been loaded"); });

Example:

$("#Id").load("url",function(){this.style.color="#f00";});//"this" is Dom-Object, current is $("#Id")[0].