--- title: 'XMLHttpRequest: loadstart イベント' slug: Web/API/XMLHttpRequest/loadstart_event tags: - API - イベント - NeedsCompatTable - NeedsSpecTable - ProgressEvent - ウェブ - XMLHttpRequest - イベント - loadstart browser-compat: api.XMLHttpRequest.loadstart_event translation_of: Web/API/XMLHttpRequest/loadstart_event --- {{APIRef}} **`loadstart`** イベントは、リクエストがデータを読み込み始めたときに発行されます。
バブリング なし
キャンセル 不可
インターフェイス {{domxref("ProgressEvent")}}
イベントハンドラープロパティ {{domxref("XMLHttpRequestEventTarget/onloadstart", "onloadstart")}}
## 例 ### ライブデモ #### 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/loadend_event", "loadend")}}, {{domxref("XMLHttpRequest/load_event", "load")}}, {{domxref("XMLHttpRequest/progress_event", "progress")}}, {{domxref("XMLHttpRequest/error_event", "error")}}, {{domxref("XMLHttpRequest/abort_event", "abort")}} - [進捗の監視](/ja/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#monitoring_progress)