我正在使用 Symfony2 和 twig 作为模板开发一个应用程序。我也在使用ajax。这是我 Controller 中代码的一部分:
public function testuaanotatuAction(Request $request)
{
if ($request->isXmlHttpRequest())
{
return $this->forward('AnotatzaileaAnotatzaileaBundle:Page:Interpretatu');
}
// Some code.....
return $this->render('AnotatzaileaAnotatzaileaBundle:Page:AnotatuInterpretazio.html.twig',
array('Azpimarratu' => $Markagarria->getMarkIdent()));
}
public function InterpretatuAction()
{
return $this->render('AnotatzaileaAnotatzaileaBundle:Page:FAQ.html.twig');
}
然后这是我在 AnotatuInterpretazio.html.twig 中的代码,我使用 JQuery 进行 Ajax 调用:
<script type='text/javascript'>
$("#ButtonId").click(function ()
{
$.ajax({
url: "{{ path('AnotatzaileaAnotatzaileaBundle_testuaanotatu') }}",
type: "POST"
});
});
</script>
如您所见,我在这里打算做的是通过模板 AnotatuInterpretazio.html.twig 调用 InterpretatuAction。然后 InterpretatuAction 将调用另一个模板。它不起作用,知道吗?
最佳答案
您需要在代码中使用.success
函数。如果你不这样做,什么都不会发生
关于javascript - Symfony2 Ajax 和 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587463/