2

我一直在使用error()Ajax 事件,$.ajax()$.ajaxSetup()有三个参数:error(xhr,status,error)我知道这些参数是什么,并且没有问题。

但无法理解 的论点.ajaxError(function(event,xhr,options,exc))任何人都可以描述这些论点,每一个。特别event论证。并且可以给我一个例子来使用四个参数中的每一个.ajaxError(function(event,xhr,options,exc))

问候

4

1 回答 1

2

我在 JQuery 论坛中讨论了我的问题并得到了有用的答案

event is an ajaxError event object and doesn't contain any particularly useful information. xhr is the jQuery wrapper around the XMLHttpRequest object that made the request - useful attributes are status and statusText. options is the full set of options sent to the ajax request - useful attributes are url, isLocal, and type. exc is the exception thrown - useful attributes are filename and message, and possibly lineNumber and columnNumber.

$('#results').ajaxError(function(event, xhr, options, exc) {
  $(this).text('Couldn\'t load ' + options.url + ' because (' +
        xhr.status + ' - ' + xhr.statusText + ') ' + exc.message);
});

并且另外研究The Event Object (page 173)JavaScript & jQuery: The Missing Manual, 2nd Edition书的部分。部分金额为:

事件对象 Whenever a web browser fires an event, it records information about the event and stores it in an event object. The event object contains information that was collected when the event occurred, like the vertical and horizontal coordinates of the mouse, the element on which the event occurred, or whether the Shift key was pressed when the event was triggered.

现在知道什么是不明白的。就一件事:

谁能明确地给我几个$.ajaxError event(parameter) attributes. 我进行调试的实例,Firebug并查看event Object并发现非常有用的信息,但我是新手,需要一些适合我的文章的功能$.ajaxError parameters.

于 2013-03-07T11:34:14.043 回答