Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用javascript或Symfony重新加载页面?_Javascript_Php_Symfony 2.8 - Fatal编程技术网

用javascript或Symfony重新加载页面?

用javascript或Symfony重新加载页面?,javascript,php,symfony-2.8,Javascript,Php,Symfony 2.8,提交表单后,关闭模式并发送成功通知。 但是,新提交的数据不会显示为已捕获,因为页面不会刷新。(无法使用PHP或javascript刷新) 在这种情况下,我认为javascript刷新是理想的——或者Symfony重定向更合适 php/symfony中的成功代码: $passthroughVars = array( 'closeModal'=> 1, 'jsContent' => 'custom_widget' ); $passthroughVars['widgetH

提交表单后,关闭模式并发送成功通知。 但是,新提交的数据不会显示为已捕获,因为页面不会刷新。(无法使用PHP或javascript刷新)

在这种情况下,我认为javascript刷新是理想的——或者Symfony重定向更合适

php/symfony中的成功代码:

$passthroughVars = array(
    'closeModal'=> 1,
    'jsContent' => 'custom_widget'
);

$passthroughVars['widgetHtml'] = $this->renderView('WidgetBundle:Widget:widget.html.php', array(
    'widget' => $widget,
));
$passthroughVars['widgetId'] = $widget->getId();
$passthroughVars['flashes'] = $this->getFlashContent();

$response = new JsonResponse($passthroughVars);
$response->headers->set('Content-Length', strlen($response->getContent()));

return $response;
Javascript:

Widgety.widgetOnLoad = function (container, response) {
    if (response) {
        if (response.upWidgetCount) {
            var count = parseInt(mQuery('#WidgetCount').html());
            count = (response.upWidgetCount > 0) ? count + 1 : count - 1;

            mQuery('#WidgetCount').html(count);
        }

        if (response.widgetHtml && response.widgetId) {
            var el = '#Widget' + response.widgetId;
            if (mQuery(el).length) {
                mQuery(el).replaceWith(response.widgetHtml);
            } else {
                mQuery('#widget-container .widget').prepend(response.widgetHtml);
            }

            mQuery(el + " *[data-toggle='ajaxmodal']").off('click.ajaxmodal');
            mQuery(el + " *[data-toggle='ajaxmodal']").on('click.ajaxmodal', function (event) {
                event.preventDefault();

                Widgety.ajaxifyModal(this, event);
            });

            mQuery(el + " *[data-toggle='confirmation']").off('click.confirmation');
            mQuery(el + " *[data-toggle='confirmation']").on('click.confirmation', function (event) {
                event.preventDefault();
                WidgetyVars.ignoreIconSpin = true;
                return Widgety.showConfirmation(this);
            });
        }

        if (response.deleted && response.widgetId) {
            var el = '#Widget' + response.widgetId;
            if (mQuery(el).length) {
                mQuery(el).remove();
            }
        }
    }
};
在javascript中,我尝试添加
document.location.reload(true)
,但内容没有刷新。 同样,通过PHP重定向,即使传递
closeModal=1
,模态也会拒绝关闭

代码:


要用Javascript重新加载网站,需要调用
window.location.reload()
函数。您还可以调用具有类似效果的
window.location.href=window.location.href
(这里已经回答了这个问题,并提供了进一步的详细信息,)


虽然我认为更好的解决方案是使用Javascript将更新的内容添加到页面中(而不是重新加载页面),但这对用户体验来说“更好”。

要用Javascript重新加载网站,需要调用
window.location.reload()
函数。您还可以调用具有类似效果的
window.location.href=window.location.href
(这里已经回答了这个问题,并提供了进一步的详细信息,)


虽然我认为更好的解决方案是使用Javascript将更新的内容添加到页面中(而不是重新加载页面),但这对用户体验来说“更好”。

如果您希望在表单提交后刷新页面(因此模式关闭)您可能想看看这个:

$('#yourModal').on('hide.bs.modal', function () {
    window.location.reload()
});

这应该行得通

如果您要查找的是在提交表单后刷新页面(因此模式关闭),您可能需要查看以下内容:

$('#yourModal').on('hide.bs.modal', function () {
    window.location.reload()
});

这应该行得通

这样做需要向模板添加一个调用,对吗?你能给我举个例子,让我更好地理解如何实现这个目标吗?这样做需要向模板添加一个调用,对吗?你能给我举个例子,让我更好地理解如何实现这一目标吗?