【问题标题】:Reload page not working after validation using JS使用JS验证后重新加载页面不起作用
【发布时间】:2019-12-11 10:26:24
【问题描述】:

所以我有一个带有 Laravel 验证的表单。如果表单没有问题(例如必填字段),则页面重新加载运行良好,但如果验证失败,则重新加载页面无法正常工作。如果单击后退按钮,我将强制页面重新加载。这是代码。

<script type="text/javascript">
    $(window).load(function() {
        $('form').get(0).reset();
    });
</script>

成功提交后,所有字段都应为空白。 在 laravel 刀片文件中实现它应该做的其他事情是什么?

【问题讨论】:

  • 如果您不使用 ajax 发送,则必须根据正确请求刷新页面。这意味着页面刷新后表单字段应该为空

标签: laravel laravel-blade reload


【解决方案1】:

你试过location.reload();吗?

【讨论】:

  • 是的,这是我的第一个解决方案,但结果与我使用的相同。
  • 你试过这个吗? stackoverflow.com/questions/6666363/…。 Chaya Cooper 回答的问题似乎与您的问题相似。
【解决方案2】:

感谢您的帮助。 我是这样做的:

<script>
    if (!!window.performance && window.performance.navigation.type === 2) {
        //navigation type 2 is accessed using back button while, 
        //0 is accessed using the link or redirected after validation and 1 is refresh page
        window.location.reload();
    }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 2016-11-26
    相关资源
    最近更新 更多