Skip to content

Instantly share code, notes, and snippets.

@suneo3476
Last active December 18, 2015 15:19
Show Gist options
  • Save suneo3476/5803534 to your computer and use it in GitHub Desktop.
Save suneo3476/5803534 to your computer and use it in GitHub Desktop.
【未実行】「パーフェクトJavaScript」p.294 リスト11.12 XMLHttpRequestのタイムアウト処理。テストしてない。
<script>
var xhr = new XMLHttpRequest();
var timerId = window.setTimeout(function() {
xhr.abort();
}, 5000); // 5秒
xhr.onreadystatechange = function() {
if (request.readyState == 4) {
// タイムアウト処理をキャンセルする
window.clearTimeout(timerId);
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment