matrix-shoutbox

git clone https://git.tarina.org/matrix-shoutbox
Log | Files | Refs

test.html (1517B)


      1 <!DOCTYPE html>
      2 <head>
      3   <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
      4   <script type="text/javascript">
      5     function refresh() {
      6       var req = new XMLHttpRequest();
      7       console.log("Grabbing Value");
      8       req.onreadystatechange = function () {
      9         if (req.readyState == 4 && req.status == 200) {
     10           document.getElementById('matrix-shoutbox').innerText = req.responseText;
     11         }
     12       }
     13       req.open("GET", 'msg.txt', true);
     14       req.send(null);
     15     }
     16 
     17     function init() {
     18       refresh()
     19       var int = self.setInterval(function () {
     20         refresh()
     21       }, 1000);
     22     }
     23   </script>
     24 </head>
     25 
     26 <body onload="init()">
     27   <div id="main">
     28     <div id="updateMe">
     29       <h2>Shout out to Radio Rymd!</h2>
     30 	<form>
     31         <input id="msg"></input>
     32         <button id="button">send</button>
     33 	</form>
     34     <span id="send">transmitting...</span>
     35       <pre id="matrix-shoutbox"></pre>
     36     </div>
     37   </div>
     38 </body>
     39 </html>
     40 
     41 <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
     42 <script>
     43 $(document).ready(function(){
     44     $('#send').hide();
     45 });
     46 $("button").click(function(e) {
     47     var msg = $("input#textfield").val()
     48     e.preventDefault();
     49     $.ajax({
     50         type: "POST",
     51         url: "/shoutout",
     52         data: {signal:msg},
     53         success: function(result) {
     54             $('#send').show(1500);
     55             $('#send').hide(1500);
     56             alert('ok');
     57         },
     58         error: function(result) {
     59             alert('error');
     60         }
     61     });
     62 });
     63 </script>