我一直在error()
和$.ajax()
中使用$.ajaxSetup()
Ajax事件,它有三个参数:error(xhr,status,error)
我知道这些参数是什么,并且没有问题
但无法理解.ajaxError(function(event,xhr,options,exc))
的论点。任何人都可以描述这四个论点中的每一个。特别event
论点。并且可以举例说明使用.ajaxError(function(event,xhr,options,exc))
此致
答案 0 :(得分:2)
我在JQuery论坛中讨论了我的问题并获得了一个有用的answer :
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.