我不知道这段代码有什么问题,没有错误,但它不起作用。我想要的是当我点击表格行时,应该出现一个包含 >all informations[web page][1] 的文本区域。*这是树枝文件:1.脚本
<script>
function detailFunction() {
$('#ligneSelectionnee').click(function () {
id=$(this).val();
$.ajax({
type:"POST",
url:'http://localhost/randonneeweb/web/app_dev.php/recDetailAjax',
dataType:"json",
data:{id:id},
success : function (response) {
if (response!=null){
document.getElementById('nothing').style.display="none";
document.querySelector("#zoneDetail").innerHTML=response.view;
}
else{
document.getElementById('nothing').style.display="block";
}
}
})
})}
</script>
- 应选择的表格行
<tbody>
{% for m in reclamations %}
<tr id="ligneSelectionnee" value="{{ m.idreclamation }}" onclick="detailFunction()">
<td> {{ m.dateReclamation|date('Y-m-d') }}</td>
<td> {{ m.typereclamation }}</td>
<td> {{ m.sujetreclamation}}</td>
<td> {{ m.message }}</td>
</tr>
{% endfor %}
</tbody>
- 应显示详细信息的 div
<div id="zoneDetail" style="margin-right: 20em">
</div>
**这是控制器中的功能:
public function afficherDetailsAction(Request $request)
{echo "hellooo";
if($request->isXmlHttpRequest())
{
$id=$request->get('id');
$em=$this->getDoctrine()->getManager();
$reclamations=$em->getRepository('RandoPlusRandoBundle:Reclamation')->findBy(array('idreclamation'=>$id));
dump($reclamations);
if($reclamations!=null)
{
return new JsonResponse(
['view'=>$this->renderView('RandoPlusRandoBundle:Reclamation:detailAjax.html.twig',array('detail'=>$reclamations))],200
);
}
}
return new Response(null);
}
*** Ajax 函数的路由:
recDetailAjax:
path: /recDetailAjax
defaults: { _controller: RandoPlusRandoBundle:Reclamation:afficherDetails }
****最后是 Ajax 用来加载细节的树枝:
<label>Description</label></br><textarea>Date : {{ detail.dateReclamation }}</br>type:{{ detail.typereclamation }}</br>Sujet:{{ detail.sujetreclamation }}</br>Message:{{ detail.message }}</textarea>
detailAjax.html.twig不是严格的 json,但您的响应是 json。你必须改变它。
当您尝试 ajax 时,您可以使用浏览器控制台网络部分。此工具中有有关请求的详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句