Create a gist now

Instantly share code, notes, and snippets.

jQuery abort() method on ajax/xhr objects triggers the error handler
import tornado.ioloop
import tornado.web
html = """
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"
type="text/javascript"></script>
<script>
var req = $.ajax({url: "/never_returns",
success: function(data) { console.log("Success"); },
error: function(xhr, text_status, error_thrown) {
console.log("Error: " + text_status); }
});
function stop() {
req.abort();
}
</script>
</head>
<body>
Fetching... (will never return)
<br><br>
<button onclick="stop()">Stop</button>
</body>
</html> """
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write(html)
class NeverReturnsHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
pass
application = tornado.web.Application(
[(r"/", MainHandler),
(r"/never_returns", NeverReturnsHandler)])
application.listen(8001)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment