我有一个非常标准的案例,我尝试通过 jQuery 的 Ajax 提交一些 JSON 数据。
我的 JavaScript 代码如下所示:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type='text/javascript' src='script.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
$("#submit").click(function() {
$.post('/test', {test : '123'}, function(data) { alert("callback received"); }, 'json');
});
});
</script>
在应用程序引擎方面,我有这个:
class Submit(webapp.RequestHandler):
def post(self):
logging.info(self.request.body)
self.response.out.write("test_response")
我收到 JSON 数据logging.info(self.request.body)
完美,但是一旦我发出响应,它就会触发错误。我得到的错误日志如下:
Exception happened during processing of request from ('192.168.2.8', 38875)
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 283, in handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/hw/Siine/google_appengine/google/appengine/tools/dev_appserver.py", line 3123, in init_
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
self.finish()
File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
self.wfile.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
我完全不知道我做错了什么,因为这看起来很简单。