【问题标题】:Formspree 400 BAD REQUESTFormspree 400 错误请求
【发布时间】:2018-03-02 15:22:13
【问题描述】:

控制台错误 - POST http://formspree.io/myemail@myemail.com 400 (BAD 请求)发送@jquery.min.js:4

我无法使用 Formspree 提交表单。错误显示:

加载资源失败:服务器响应状态为 400 (错误请求)

我尝试将 URL 更改为 https://formspree.io/myemail@myemail.com。在过去的 10 天里,我一直面临这个问题,在此之前没有任何问题。这是在 Google chrome 版本 64 上测试的。有人可以帮我解决这个问题。

【问题讨论】:

  • 请向我们展示您的代码,因为您当前形式的问题过于宽泛。
  • 修正错误引号

标签: http-status-code-400


【解决方案1】:

很遗憾,AJAX 提交现在只供 Formspree 上的金牌用户使用。

要解决这个问题,您可以创建一个 <form> 元素并以编程方式提交它,如下所示:

function submitForm(name, email, message){
    var destinationEmail = "youremail@domain.com";
    var form = document.createElement('form');
    form.setAttribute("action", "https://formspree.io/" + destinationEmail)
    form.setAttribute("method", "POST")

    // Subject for your email
    var field = document.createElement("input");
    field.setAttribute("type", "hidden");
    field.setAttribute("name", "_subject");
    field.setAttribute("value", "Contact form submitted");
    form.appendChild(field);

    // Contact email address        
    field = document.createElement("input");
    field.setAttribute("type", "hidden");
    field.setAttribute("name", "email");
    field.setAttribute("value", email);
    form.appendChild(field);

    // Your user's name
    field = document.createElement("input");              
    field.setAttribute("type", "hidden");
    field.setAttribute("name", "name");
    field.setAttribute("value", name);
    form.appendChild(field);

    // The text message
    field = document.createElement("input");              
    field.setAttribute("type", "hidden");
    field.setAttribute("name", "message");
    field.setAttribute("value", message);
    form.appendChild(field);

    document.body.appendChild(form);    
    form.submit();
}

submitForm("Your user's name", "user@domain.com", "Here is my message");

缺点是你的邮箱地址会显示在地址栏上,并且浏览器会在继续之前显示一个验证码。

但是,我发现在多次提交后,Rest API 实际上开始正常工作。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    相关资源
    最近更新 更多