1

在我的应用程序中,我在页面加载时使用 Jquery 触发 Ajax 获取请求。如果调用花费了异常长的时间,则用户可能会在其标准浏览会话期间导航离开初始页面。最终,这个 ajax 调用完成并返回一个响应。问题是,此时用户已经离开了页面,并且没有任何东西在监听响应。发生这种情况时,我会在日志中收到此异常。

----------------------------------------
Exception happened during processing of request from ('98.x.x.x', 36495)
Traceback (most recent call last):
  File "M:\Python2.7\App\lib\SocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "M:\Python2.7\App\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "M:\Python2.7\App\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "M:\Python2.7\App\lib\SocketServer.py", line 640, in __init__
    self.finish()
  File "M:\Python2.7\App\lib\SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "M:\Python2.7\App\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------

我怎样才能防止这种情况发生?

例外中列出的所有文件都不是我的代码。

4

2 回答 2

1

这个问题在功能上与How to cancel an ajax request in Django when new page is requested相同,答案是一样的。

于 2013-08-28T20:16:36.193 回答
0

这只会在您使用 django 开发服务器时发生,该服务器会尝试在控制台上记录异常。

但是,对于其他网络服务器(如 apache),您会得到类似的异常,但可能没有那么多描述性。

于 2012-09-01T07:19:56.070 回答