Commits

Colin Copeland  committed 2f96a52

add proper $.ajax call; tornado automatically writes json if given dict, so remove json stuff

  • Participants
  • Parent commits 98f496b

Comments (0)

Files changed (2)

File tic-tac-toe/media/game.js

     board = game.board;
     turn *= -1;
     
-    
-    data = {'board': JSON.stringify(board)};
-    $.post('http://localhost:8888/', data, function(response) {
-        console.log(response);
+    $.ajax({
+        url: 'http://localhost:8888/',
+        type: 'POST',
+        data: JSON.stringify({'board': board}),
+        dataType: 'json',
+        // contentType: 'json',
+        processData: false,
+        success: function(response) {
+            console.log(response);
+        }
     });
 }
 

File tic-tac-toe/server/tttserv.py

 
 import sys
 import unittest
+import logging
+import pprint
 
 import tornado.httpserver
 import tornado.httpclient
 
 import simplejson as json
 
+logging.basicConfig(level=logging.DEBUG)
+
 class TestTicTacToe(unittest.TestCase):
     response = None
 
             raise tornado.web.HTTPError(500, "Board not found.")
         board = json.loads(board_json)['board']
         new_board = move(board)
-        new_board_json = json.dumps({ 'board' : new_board })
-        self.write(json.dumps(new_board_json))
+        self.write({'board' : new_board})
+        self.flush()
+        self.finish()
 
     def get(self):
         pass