--- title: EventSource.onerror slug: Web/API/EventSource/error_event translation_of: Web/API/EventSource/onerror original_slug: Web/API/EventSource/onerror ---
{{domxref("EventSource")}} 的属性 onerror 是当发生错误且这个错误事件({{event("error")}} )被EventSource触发时调用的一个事件处理函数({{event("Event_handlers", "event handler")}})
eventSource.onerror = function
evtSource.onerror = function() {
console.log("EventSource failed.");
};
Note: 你可以在Github上查看这个完整例子: Simple SSE demo using PHP.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG', "comms.html#handler-eventsource-onerror", "onerror")}} | {{Spec2('HTML WHATWG')}} | Initial definition |