【问题标题】:I want to redirect to a new page after submitting [closed]提交后我想重定向到新页面[关闭]
【发布时间】:2014-12-22 19:59:04
【问题描述】:

我有一个购物车页面。我想在哪里获取有关我的客户的信息。我有一个提交按钮

<input type="button" id="submit-cart" value='Submit' onclick="submit_cart()" />

我想在提交表单 onclick 后重定向到新页面。

【问题讨论】:

  • 你有没有花时间研究/搜索这个?有很多方法可以做到这一点。
  • Chris Coyier 前几天刚刚发布了这个:css-tricks.com/redirect-web-page
  • 在处理表单提交的同一个地方执行此操作,无论是服务器端、JS 还是 w/e。处理完表单后,您可以使用您的 JS、PHP、w/e 进行重定向。

标签: javascript php jquery mysql


【解决方案1】:

使用window.location = url 重定向

所以这看起来像

function submit_cart() {
    var url = 'xyz.com' // Some url you want to redirect to
    window.location = url;
}

在 php 中,您可以使用 header 函数来做到这一点:

<?php
  header('Location: xyz.com'); // xyz.com is the url you want to redirect to
  exit();
?>

【讨论】:

    【解决方案2】:
    function submit_cart () {
    
    /* do something amazing you always wanted to do with the user's data */
    window.location.assign('/* here comes the url the user should be sent to */');
    }
    

    或者,根本没有 javascript:

    <form action = "url to redirect to" method="<!-- POST / GET -->">
      <input type="text" name="textinput"/>
      <input type="submit" class="button" id="submit-cart" value='Submit'/>
    </form>
    

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      • 2012-03-29
      • 1970-01-01
      • 2013-04-17
      相关资源
      最近更新 更多