提交表单后,模式将关闭,并发送成功通知。 但是,新提交的数据不会像捕获那样显示,因为页面不会刷新。 (不能让它刷新PHP或JavaScript)用javascript或Symfony重新载入页面?
在这种情况下,我会假设一个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
。
代码:
return $this->redirect($this->generateUrl('widget_page',
array(
'passthroughVars' => array(
'closeModal' => 1,
),
'widgetAction' => 'overview',
'widgetId' => $widget->->getId()
)
));
这样做需要添加一个调用模板,是否正确?你能否指点我一个例子,以便我更好地理解如何实现这样的目标? – bottomrocks