client/scripts/client.js
author Eugen Sawin <sawine@me73.com>
Thu, 06 Oct 2011 02:05:43 +0200
changeset 8 c926073022f4
parent 5 fdf35f8d7ff8
child 9 44d912089ce1
permissions -rw-r--r--
Some improvs.
     1 //--allow-file-access-from-files
     2 var server = "http://localhost:8080";
     3 var view_left = "<view-left><h2>Machine</h2><p>Be yourself within Machine.</p></view-left>";
     4 
     5 function command()
     6 {
     7     var com = document.getElementById("com");
     8     $.ajax({url: server + "/com",
     9 	    data: com.value,
    10 	    success: callback});
    11     com.value = ""; 
    12 }
    13 
    14 function callback(msg)
    15 {
    16     alert(msg); 
    17     view_left = "<view-left><h2>Machine</h2><p>" + msg.time + "</p></view-left>";
    18     $("view-left").replaceWith(view_left);   
    19 }
    20 
    21 $(document).ready
    22 (
    23     function()
    24     {
    25 	$("view-left").replaceWith(view_left);
    26     }
    27 );
    28 
    29 $(document).keypress
    30 (
    31     function(event) 
    32     {
    33 	if (event.which == 13) 
    34 	{
    35 	    event.preventDefault();
    36 	    command();
    37 	}
    38     }
    39 );