Last active
January 2, 2018 02:37
-
-
Save externvoid/edcba0d9dfd57bde5f7da41bd73efe87 to your computer and use it in GitHub Desktop.
同期通信テスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <!-- https://www.ajaxtower.jp/ini/http/index3.html --> | |
| <!-- 同期通信によるファイルの取得 --> | |
| <html lang="ja"> | |
| <head> | |
| <meta http-equiv="Content-Type" Content="text/html;charset=UTF-8"> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript"> | |
| <title>同期通信テスト</title> | |
| <script type="text/javascript"> | |
| function loadText(){ | |
| var xmlHttp; | |
| xmlHttp = new XMLHttpRequest(); | |
| xmlHttp.open("GET", "http://stocks.hopto.org/json", false); | |
| xmlHttp.send(null); | |
| var data = xmlHttp.responseText; | |
| var obj = (new Function("return " + data))(); | |
| var ar = obj["foo"]; | |
| alert(ar[0] + ar[1]); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <h1>同期通信テスト</h1> | |
| <form> | |
| <input type="button" value="ファイル読み込み" onClick="loadText()"> | |
| </form> | |
| </body> | |
| </html> | |
| <!-- https://www.ajaxtower.jp/ini/http/index3.html --> | |
| <!-- 同期通信テスト--> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
openメソッドの第三引数はasyncならtrue, syncならfalse。syncの場合、send(null);メソッドで通信開始。本当なら、エラー処理が必要。
Functionコンストラクタ関数で文字列リテラルから、関数オブジェクトを生成し、受信したテキストをjsonに変換。