【问题标题】:Form is not submitting via Firefox表单未通过 Firefox 提交
【发布时间】:2018-08-18 11:44:40
【问题描述】:

我的表单在 Chrome、Safari 上运行良好,但在 Firefox 上运行良好。

尝试#1

<form id="subscribe-form" class="footer-sign-up" action="/subscribe" method="POST">
    <input type="text" placeholder="First Name" name="first_name" id="fname" required>
    <input type="text" placeholder="Last Name" name="last_name" id="lname" required>
    <input id="footer-email" type="text" placeholder="Your Email Address" name="email" required>
    

    <input type="submit" id="subscribe" class="signupbtn" value="sign up">

</form>

尝试#2

<form id="subscribe-form" class="footer-sign-up" action="/subscribe" method="POST">
    <input type="text" placeholder="First Name" name="first_name" id="fname" required>
    <input type="text" placeholder="Last Name" name="last_name" id="lname" required>
    <input id="footer-email" type="text" placeholder="Your Email Address" name="email" required>
    
    
    <button type="submit" id="subscribe" class="signupbtn">sign up</button>

</form>

结果

网络标签

标题

参数

如何进一步调试?

【问题讨论】:

  • 提交时控制台有错误吗?
  • 您是否在 FireFox 的调试器中遇到任何错误? F12 应该打开它,您可以检查 ConsoleNetwork 选项卡中的前端/后端错误(分别)
  • @Jeff,控制台看起来很干净。我收到此错误The page has expired due to inactivity. Please refresh and try again.
  • @TimLewis,在“网络”选项卡中,我看到 2 个帖子。 1 是200,1 是419,将在帖子中添加截图。
  • Response 选项卡中有什么?

标签: html ajax forms laravel firefox


【解决方案1】:

我想我可能找到了一些东西;如果您通过 AJAX 提交,但没有阻止页面提交,您将遇到问题。

将部分代码更改为:

$('#subscribe').click(function(e){
  e.preventDefault();
  ...

这应该只做 AJAX 提交,而不是刷新页面。

我还可以通过将 button type="submit" 更改为 button type="button" 来通过 FireFox 提交,这样它就不会在本机上提交页面。

【讨论】:

    【解决方案2】:

    您需要在表单中添加一个 CSRF 令牌。假设这是一个刀片文件:

    <form id="subscribe-form" class="footer-sign-up" action="/subscribe" method="POST">
      {{ csrf_field() }}
      <input type="text" placeholder="First Name" name="first_name" id="fname" required>
      <input type="text" placeholder="Last Name" name="last_name" id="lname" required>
      <input id="footer-email" type="text" placeholder="Your Email Address" name="email" required>
    <input type="submit" id="subscribe" class="signupbtn" value="sign up">
    

    当 Laravel 中的页面加载时,您可以打印一个 CSRF 或跨站点请求伪造令牌,这在一定时间内是有效的。任何 POST 请求都需要有一个当前的,否则 Laravel 会给你一个页面过期错误。

    【讨论】:

    • 这是正确的,但并不能真正解释为什么它适用于 Chrome/Safari 而不是 Firefox。会吗?
    • 现在测试,似乎面临同样的结果。第一次尝试。现在会再做一次。
    • 我需要在我的元部分添加这一行吗?在我的 master.balde.php 上?
    • 现在试试。
    • @TimLewis 不,它没有解释这一点。我也不能——但是当我看到这个错误时我就知道了,所以认为这将是开始的地方。
    猜你喜欢
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多