Wentao Shang | f8b4a7d | 2012-12-25 12:52:07 -0800 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
| 4 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 5 | <meta charset="UTF-8">
|
| 6 |
|
| 7 | <head>
|
| 8 | <title>HTTP Get via XHR</title>
|
| 9 |
|
| 10 | <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
|
| 11 |
|
| 12 | <script type="text/javascript">
|
| 13 | function run() {
|
| 14 | var xhr = new XMLHttpRequest();
|
| 15 | var url = document.getElementById('interest').value;
|
| 16 | xhr.open("GET", url, true);
|
| 17 | //xhr.responseType = "arraybuffer";
|
| 18 | var T0 = new Date();
|
| 19 | xhr.onload = function(e) {
|
| 20 | //var arraybuffer = xhr.response; // not responseText
|
| 21 | /* ... */
|
| 22 | //document.getElementById('content').innerHTML += xhr.responseText;
|
| 23 | var T1 = new Date();
|
| 24 | document.getElementById('content').innerHTML += "<p>Time elapsed: " + (T1 - T0) + " ms</p>";
|
| 25 | document.getElementById('content').innerHTML += "<p>Buffer size: " + xhr.responseText.length + "</p>";
|
| 26 | };
|
| 27 | xhr.send();
|
| 28 | }
|
| 29 |
|
| 30 | </script>
|
| 31 |
|
| 32 | </head>
|
| 33 | <body >
|
| 34 |
|
| 35 | <form>
|
| 36 | Please Enter an Interest:<br />
|
| 37 | <input id="interest" type="text" name="INTEREST" size="50" value="marsgale_curiosity_1452.jpg" />
|
| 38 | </form>
|
| 39 |
|
| 40 | <button onclick="run()">Fetch Content</button>
|
| 41 |
|
| 42 | <p id="content">Result: <br/></p>
|
| 43 |
|
| 44 | </body>
|
| 45 | </html>
|