gpt4 book ai didi

javascript - 获取 "Broken pipe from (' 127.0.0。 1', 33187)"使用 $.ajax 进行获取请求时

转载 作者:行者123 更新时间:2023-11-30 12:02:54 25 4
gpt4 key购买 nike

我正在尝试使用 form 异步提交表单标签,<input type='submit' method=get>jQuery

当我点击提交按钮时,我的终端回溯中出现以下错误:

[24/Mar/2016 03:55:14] "GET /? HTTP/1.1" 200 1270
[24/Mar/2016 03:55:14] "GET /submitted/1458791714827 HTTP/1.1" 302 0
- Broken pipe from ('127.0.0.1', 33187)
这是我的 HTML...

<body>
<h1>API: Disney</h1>
<form method="get">
<input type='submit' value='CLICK ME VIEW ALL TIMESTAMPS BETWEEN NOW AND 5 MINUTES AGO!'></input>
</form>
</body>

这是我的 jQuery...

$(document).ready(function(){
$('form').submit(function(){
var submittime = new Date().getTime()
$.ajax({
url: 'submitted/' + submittime,
});
});
})

这是我的 View ...

class SubmitValue(View):
def get(self, request, currdate):
val = random.randrange(1,100)
date = int(currdate)
Data.objects.create(value=val, curr_time=date)
return redirect('/')

这是我的应用程序 urls.py 文件...

url(r'^submitted/(?P<currdate>\d+)$', SubmitValue.as_view()),

这是我的模型...

from django.db import models

class Data(models.Model):
value = models.IntegerField()
curr_time = models.BigIntegerField()

最佳答案

当点击 input type=submit 时,因为我将 method="get' 放在了 form 标签中,它发送了一个与 $.ajax get 请求同时运行的不必要的 get 请求。这会导致 broken pipe 错误。为了摆脱它,我只是提取了 method= 'get' 脱离 form 标记,因此当用户单击 input type=submit 时,它只发送一个 get 请求。

像这样!

<body>
<h1>API: Disney</h1>
<form>
<input type='submit' value='CLICK ME VIEW ALL TIMESTAMPS BETWEEN NOW AND 5 MINUTES AGO!'></input>
</form>
</body>

关于javascript - 获取 "Broken pipe from (' 127.0.0。 1', 33187)"使用 $.ajax 进行获取请求时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com