【问题标题】:Redirect to another page with data使用数据重定向到另一个页面
【发布时间】:2020-03-15 23:59:05
【问题描述】:

我在第 1 页有一个 Javascript 数组,我在第 2 页需要它。

我尝试使用 JQuery post 方法,但我无法使其工作:

   $.post( "{{path('result')}}", mydata );

如何使用该数组正确地将用户从第 1 页重定向到第 2 页?

cookie 或会话在这种情况下有用吗?

我将 Symfony4 与 Twig 一起使用。

谢谢。

【问题讨论】:

  • 可以包含mydata代码吗?
  • 嗨,我还没有编码,它应该是一个javascript数组。我试过这个: $.post("{{path('result')}}");我无法让它工作。所以我真的会在我成功后放数据。

标签: javascript jquery symfony twig symfony4


【解决方案1】:

首先,您需要使用 jQuery post() 将数据发布到第 1 页。然后在第 1 页控制器操作中,您需要重定向到第 2 页控制器。你可以看看这个链接 (https://symfony.com/doc/current/controller/forwarding.html)

public function index($name)
{
    $response = $this->forward('App\Controller\OtherController::fancy', [
        'name'  => $name,
        'color' => 'green',
    ]);

    // ... further modify the response or return it directly

    return $response;
}

public function fancy($name, $color)
{
    // ... create and return a Response object
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    相关资源
    最近更新 更多