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

标签 javascript jquery python ajax django

我正在尝试使用 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,
        });
    });
})

这是我的观点...

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 pipeline 错误。为了摆脱它,我只是拉出了 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。使用 $.ajax 执行 get 请求时出现 1', 33187)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193114/

相关文章:

javascript - React.js : Set image as div background inside map function

javascript - 如何在表单操作或 window.location(PHP) 中使用数据切换?

javascript - img onclick 不起作用

javascript - 在加载整个 html 页面之前如何显示加载 gif

python - Python 2.x 中的 nonlocal 关键字

javascript - 如果使用 javascript 输入为空,如何防止提交

javascript - 将compositeView选项传递给itemView

javascript - 从 ReactJS 应用程序调用 CMD 命令行

javascript - CORS 和 Angular header 身份验证的烦人问题

python - 如何从 Python Azure Function App 查看错误日志?