使用AJAX更改Twig模板变量 [英] Change Twig Template variable with AJAX

查看:169
本文介绍了使用AJAX更改Twig模板变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我使用AJAX获得的新值重新加载html的一部分.

I'am trying to reload a part of my html with a new value that I've got using AJAX.

有一个

{% for client in clients %} 

循环,我使用AJAX获得了一组新的客户端:

loop, and i've got a new set of clients using AJAX :

        $search = $request->request->get('data');

        $clients=$this->getDoctrine()->getRepository(
        Client::class)->findBy(array('name'=>$search));

        $response = new JsonResponse();
        $response->setStatusCode(200);
        return $response->setData(['search' => $clients ]);

我正在尝试使用新获取的数据来更改客户端.

I'm trying to change clients with the newly retrieved data.

有办法吗?还是我应该尝试其他技术?

Is there a way to do it ? Or should I try another technique ?

提前谢谢!

推荐答案

您无法执行此操作,因为在服务器端渲染了树枝.您将需要更新由 {%为client%s中的client%} 生成的HTML使用javascript

you could not do that because twig is rendered at the server side. you will need to update the HTML generated by {% for client in clients%} using javascript

这篇关于使用AJAX更改Twig模板变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆