client/scripts/client.js
author Eugen Sawin <sawine@me73.com>
Sat, 08 Oct 2011 01:05:50 +0200
changeset 9 44d912089ce1
parent 8 c926073022f4
child 10 ab694dc54515
permissions -rw-r--r--
Basic JSON response.
     1 //--allow-file-access-from-files
     2 var server = "http://127.0.0.1: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 	    dataType: "json",
    11 	    success: callback});
    12     com.value = ""; 
    13 }
    14 
    15 function callback(data, status, xhr)
    16 {
    17     view_left = "<view-left><h2>Machine</h2><p>" + data.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 );