win10 ajax post 400,Django[WinError 10053]在AJAX POST上

在使用Django构建的网站中,开发者遇到一个问题:当尝试通过AJAX发送用户输入的总时间时,服务器返回错误。错误日志显示连接被主机软件中断,可能是POST请求处理的问题。尽管视图中的print语句显示正常,但返回HTTP响应时出现异常,导致'NoneType'对象无法被订阅。jQuery代码中包含了捕获用户键入时间并POST到服务器的逻辑。
摘要由CSDN通过智能技术生成

我正在用Django制作一个网站,它使用AJAX将一些信息发布到后端。本例中的信息是用户键入的总时间(从开始键入时起)到按submit时的总时间。但是,由于某些原因,我一直在命令提示符下看到错误。浏览器控制台只有0:,这表示POST中的错误。我在视图中有一组print语句,它们处理post(passage_result)来帮助定位错误,而且它似乎与return HttpResponse(json.dumps(response_data), content_type="text/html")行有关,因为每个print语句都返回预期的答案。在

错误如下:[04/Jan/2015 10:30:40] "POST /typer/passage_result/ HTTP/1.1" 200 140

Traceback (most recent call last):

File "C:\Python34\lib\wsgiref\handlers.py", line 138, in run

self.finish_response()

File "C:\Python34\lib\wsgiref\handlers.py", line 180, in finish_response

self.write(data)

File "C:\Python34\lib\wsgiref\handlers.py", line 274, in write

self.send_headers()

File "C:\Python34\lib\wsgiref\handlers.py", line 332, in send_headers

self.send_preamble()

File "C:\Python34\lib\wsgiref\handlers.py", line 255, in send_preamble

('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')

File "C:\Python34\lib\wsgiref\handlers.py", line 453, in _write

self.stdout.write(data)

File "C:\Python34\lib\socket.py", line 391, in write

return self._sock.send(b)

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

[04/Jan/2015 10:30:40] "POST /typer/passage_result/ HTTP/1.1" 500 59

----------------------------------------

Exception happened during processing of request from ('127.0.0.1', 58785)

Traceback (most recent call last):

File "C:\Python34\lib\wsgiref\handlers.py", line 138, in run

self.finish_response()

File "C:\Python34\lib\wsgiref\handlers.py", line 180, in finish_response

self.write(data)

File "C:\Python34\lib\wsgiref\handlers.py", line 274, in write

self.send_headers()

File "C:\Python34\lib\wsgiref\handlers.py", line 332, in send_headers

self.send_preamble()

File "C:\Python34\lib\wsgiref\handlers.py", line 255, in send_preamble

('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')

File "C:\Python34\lib\wsgiref\handlers.py", line 453, in _write

self.stdout.write(data)

File "C:\Python34\lib\socket.py", line 391, in write

return self._sock.send(b)

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Python34\lib\wsgiref\handlers.py", line 141, in run

self.handle_error()

File "C:\Python34\lib\wsgiref\handlers.py", line 368, in handle_error

self.finish_response()

File "C:\Python34\lib\wsgiref\handlers.py", line 180, in finish_response

self.write(data)

File "C:\Python34\lib\wsgiref\handlers.py", line 274, in write

self.send_headers()

File "C:\Python34\lib\wsgiref\handlers.py", line 331, in send_headers

if not self.origin_server or self.client_is_modern():

File "C:\Python34\lib\wsgiref\handlers.py", line 344, in client_is_modern

return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'

TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Python34\lib\socketserver.py", line 613, in process_request_thread

self.finish_request(request, client_address)

File "C:\Python34\lib\socketserver.py", line 344, in finish_request

self.RequestHandlerClass(request, client_address, self)

File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 129

, in __init__

super(WSGIRequestHandler, self).__init__(*args, **kwargs)

File "C:\Python34\lib\socketserver.py", line 669, in __init__

self.handle()

File "C:\Python34\lib\wsgiref\simple_server.py", line 133, in handle

handler.run(self.server.get_app())

File "C:\Python34\lib\wsgiref\handlers.py", line 144, in run

self.close()

File "C:\Python34\lib\wsgiref\simple_server.py", line 35, in close

self.status.split(' ',1)[0], self.bytes_sent

AttributeError: 'NoneType' object has no attribute 'split'

----------------------------------------

以下是passage_result视图:

^{pr2}$

这是我的jQuery代码://Create a time so we can update it later

var time = (new Date()).getTime();

//function to update the time when the user starts typing

$('#id_user_passage').on('keyup', function (event) {

event.preventDefault();

time = (new Date()).getTime();

});

// function to get the total time the user typed from when he started to when

// he clicked the submit button, and POST the information to the backend,

// along with what he typed and when he submitted it.

$('#passage_result_form').on('submit', function(event) {

event.preventDefault();

var total_time = (new Date()).getTime() - time;

var current_time = (new Date()).getTime();

console.log('Time passed : ' + total_time + ' milliseconds');

console.log('form submitted!')

$.ajax({

url: "/typer/passage_result/",

type: "POST",

data: { 'user_passage': $('#id_user_passage').val(), 'original_passage': $("#name").text(), 'time_taken': total_time,

'creation_time' : current_time},

success: function (json) {

total_time = 0;

console.log(json);

console.log("success");

},

error: function (xhr, errmsg, err) {

$('#results').html("

Oops! We have encountered an error: " + errmsg +

" ×

");

console.log(xhr.status + ": " + xhr.responseText);

}

});

location.replace('/typer/result/');

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值