Skip to content

Instantly share code, notes, and snippets.

@suneo3476
Created June 17, 2013 19:01
Show Gist options
  • Save suneo3476/5799367 to your computer and use it in GitHub Desktop.
Save suneo3476/5799367 to your computer and use it in GitHub Desktop.
【未解決】同期通信のXMLHttpRequest。 Firefoxだと「NS_ERROR_FAILURE: Failure」 Chromeだと「Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 」 かと言って同期通信するケースって殆ど無いし、ユーザビリティ下げるしなぁ。 解決方法知っとくべきなのかなぁ。誰か知ってたら教えて。
<!DOCTYPE HTML5>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>This is test for XMLHttpRequest.</div>
<script>
var xhr = XMLHttpRequest();
xhr.open('GET', 'http://suneo3476.net', false); // 第三引数にfalseを指定して同期通信する
xhr.send(null); // ここでクライアント側の処理は待機となる
// ここにくるときはレスポンスの受信は完了している
xhr.setRequestHeader('IF-Modified-Since', 'Thu, 01, Jun 1970 00:00:00 GMT');
if (xhr.status == 200) {
alert(xhr.responseText);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment