UNPKG

ndn-js

Version:

A JavaScript client library for Named Data Networking

63 lines (53 loc) 2.33 kB
<?xml version = "1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <!-- * Copyright (C) 2014-2019 Regents of the University of California. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * A copy of the GNU Lesser General Public License is in the file COPYING. --> <html xmlns = "http://www.w3.org/1999/xhtml"> <meta charset="UTF-8"> <head> <title>HTTP Get via XHR</title> <script type="text/javascript" src="../../build/ndn.js"></script> <script type="text/javascript"> function run() { var xhr = new XMLHttpRequest(); var url = document.getElementById('interest').value; xhr.open("GET", url, true); //xhr.responseType = "arraybuffer"; var T0 = new Date(); xhr.onload = function(e) { //var arraybuffer = xhr.response; // not responseText /* ... */ //document.getElementById('content').innerHTML += xhr.responseText; var T1 = new Date(); document.getElementById('content').innerHTML += "<p>Time elapsed: " + (T1 - T0) + " ms</p>"; document.getElementById('content').innerHTML += "<p>Buffer size: " + xhr.responseText.length + "</p>"; }; xhr.send(); } </script> </head> <body > <form> Please Enter an Interest:<br /> <input id="interest" type="text" name="INTEREST" size="50" value="marsgale_curiosity_1452.jpg" /> </form> <button onclick="run()">Fetch Content</button> <p id="content">Result: <br/></p> </body> </html>