game-client.js
function onPieceDrop(event, ui) {
    var col = $(this).data().col;
    var row = $(this).data().row;
    var piece = $(ui.draggable).data().piece;
    $.ajax({
        type: 'POST',
        url: "/games/" + enc($.cookie("game")) + "/board",
        data: {
            shape: piece.shape,
            color: piece.color,
            row: row,
            column: col
        },
        success: function() {
            $(ERRORS).empty();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $(ERRORS).empty();
            $(ERRORS).append("<div class='error'>&#9888; "+jqXHR.responseText+"</div>");
        },
        complete: function() {
            $.getJSON("/games/" + enc($.cookie("game")) +
                      "/players", drawTurnInfo);
        }
    });
}
function onPieceDrop(event, ui) {
    var col = $(this).data().col;
    var row = $(this).data().row;
    var piece = $(ui.draggable).data().piece;
    $.ajax({
        type: 'POST',
        url: "/games/" + enc($.cookie("game")) + "/board",
        data: {
            shape: piece.shape,
            color: piece.color,
            row: row,
            column: col
        },
        success: function() {
            $(ERRORS).empty();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $(ERRORS).empty();
            $(ERRORS).append("<div class='error'>&#9888; "+jqXHR.responseText+"</div>");
        },
        complete: function() {
            $.getJSON("/games/" + enc($.cookie("game")) +
                      "/players", drawTurnInfo);
        }
    });
}
function onPieceDrop ( event , ui ) { var col = $ ( this ) . data ( ) . col ; var row = $ ( this ) . data ( ) . row ; var piece = $ ( ui . draggable ) . data ( ) . piece ; $ . ajax ( { type : 'POST' , url : "/games/" + enc ( $ . cookie ( "game" ) ) + "/board" , data : { shape : piece . shape , color : piece . color , row : row , column : col } , success : function ( ) { $ ( ERRORS ) . empty ( ) ; } , error : function ( jqXHR , textStatus , errorThrown ) { $ ( ERRORS ) . empty ( ) ; $ ( ERRORS ) . append ( "<div class='error'>&#9888; " + jqXHR . responseText + "</div>" ) ; } , complete : function ( ) { $ . getJSON ( "/games/" + enc ( $ . cookie ( "game" ) ) + "/players" , drawTurnInfo ) ; } } ) ; }
When piece is dropped, send a POST to the server to add to board. Either the
piece will be added or we get an error back for invalid placements.
When piece is dropped send a POST to the server to add to board . Either the piece will be added or we get an error back for invalid placements .