【问题标题】:CakePHP submit form then redirect not workingCakePHP 提交表单然后重定向不起作用
【发布时间】:2014-02-12 19:48:38
【问题描述】:

我正在尝试创建一个提交表单然后重定向到另一个页面的按钮。

$('#saveApp').click(function() {
        event.preventDefault();
        $("form[id='CustomerSaveForm']").submit(); // use the native submit method of the form element
        window.location.href = "<?php echo EWConfig::$URL?>/ExpressWay/ProgramApplications/sales/residence";

        return true;
    });

这将重定向但不提交表单,尽管注释掉 event.preventDefault() 会起到相反的作用。

【问题讨论】:

  • 有什么理由不从服务器端重定向?
  • 仅在单击此按钮时重定向。另一个按钮提交表单并且不重定向。所以我不认为服务器端是最好的选择。
  • 您可以使用ajax 发布然后$.post(...) 使用done 事件来确保何时重定向(也有助于对验证等进行排序),更多信息在这里api.jquery.com/jQuery.post
  • 我们最终选择了服务器端解决方案。感谢您的帮助!
  • window.location.href = "/ExpressWay/ProgramApplications/sales/residence";应该是 = =EWConfig::$URL;?> + "/ExpressWay/ProgramApplications/sales/residence";我认为。也有可能 php 块也必须用引号括起来。

标签: javascript jquery forms cakephp redirect


【解决方案1】:

最终使用了服务器端解决方案。

查看

echo $this->Form->button('Save and Redirect', array('name' => 'data[redirect]'));

控制器

if(!is_null($this->request->data('redirect'))){
    $this->redirect(array('controller' => 'Program', 'action' => 'index'));
}

【讨论】:

    猜你喜欢
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    相关资源
    最近更新 更多