client/scripts/client.js
author Eugen Sawin <sawine@me73.com>
Sun, 11 Dec 2011 02:27:29 +0100
changeset 10 ab694dc54515
parent 9 44d912089ce1
permissions -rw-r--r--
Added logging and Request classes.
     1 //--allow-file-access-from-files
     2 var server = "http://localhosts:8080";
     3 var view_left = "<view-left><h2>Machine</h2><p>Be yourself within Machine.</p></view-left>";
     4 
     5 function command() {
     6     var com = document.getElementById("com");
     7     $.ajax({url: server + "/com",
     8 	    data: com.value,
     9 	    dataType: "json",
    10 	    success: callback});
    11     com.value = ""; 
    12 }
    13 
    14 function callback(data, status, xhr) {
    15     view_left = "<view-left><h2>Machine</h2><p>" + data.time + "</p></view-left>";
    16     $("view-left").replaceWith(view_left);   
    17 }
    18 
    19 $(document).ready (
    20     function() {
    21 	$("view-left").replaceWith(view_left);
    22     }
    23 );
    24 
    25 $(document).keypress (
    26     function(event) {
    27 	if (event.which == 13) {
    28 	    event.preventDefault();
    29 	    command();
    30 	}
    31     }
    32 );