---
title: 'XMLHttpRequest: abort イベント'
slug: Web/API/XMLHttpRequest/abort_event
tags:
- API
- イベント
- ProgressEvent
- ウェブ
- XMLHttpRequest
- abort
browser-compat: api.XMLHttpRequest.abort_event
translation_of: Web/API/XMLHttpRequest/abort_event
---
{{APIRef}}
`abort` イベントは、例えばプログラムが {{domxref("XMLHttpRequest.abort()")}} を呼び出した時など、リクエストが中断されたときに発行されます。
バブリング |
なし |
キャンセル |
不可 |
インターフェイス |
{{domxref("ProgressEvent")}} |
イベントハンドラープロパティ |
{{domxref("XMLHttpRequestEventTarget/onabort", "onabort")}}
|
## 例
### ライブデモ
#### HTML
```html
```
```css hidden
.event-log {
width: 25rem;
height: 4rem;
border: 1px solid black;
margin: .5rem;
padding: .2rem;
}
input {
width: 11rem;
margin: .5rem;
}
```
#### JS
```js
const xhrButtonSuccess = document.querySelector('.xhr.success');
const xhrButtonError = document.querySelector('.xhr.error');
const xhrButtonAbort = document.querySelector('.xhr.abort');
const log = document.querySelector('.event-log');
function handleEvent(e) {
log.textContent = log.textContent + `${e.type}: ${e.loaded} bytes transferred\n`;
}
function addListeners(xhr) {
xhr.addEventListener('loadstart', handleEvent);
xhr.addEventListener('load', handleEvent);
xhr.addEventListener('loadend', handleEvent);
xhr.addEventListener('progress', handleEvent);
xhr.addEventListener('error', handleEvent);
xhr.addEventListener('abort', handleEvent);
}
function runXHR(url) {
log.textContent = '';
const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
}
xhrButtonSuccess.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg');
});
xhrButtonError.addEventListener('click', () => {
runXHR('https://somewhere.org/i-dont-exist');
});
xhrButtonAbort.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg').abort();
});
```
#### 結果
{{ EmbedLiveSample('Live_example', '100%', '150px') }}
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- 関連イベント: {{domxref("XMLHttpRequest/loadstart_event", "loadstart")}}, {{domxref("XMLHttpRequest/load_event", "load")}}, {{domxref("XMLHttpRequest/progress_event", "progress")}}, {{domxref("XMLHttpRequest/error_event", "error")}}, {{domxref("XMLHttpRequest/loadend_event", "loadend")}}
- [進捗の監視](/ja/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#monitoring_progress)