weixin_33713707 2017-03-25 12:04 采纳率: 0%
浏览 30

带有symfony3的Ajax Jquery

i don't know what is wrong with this code, no errors but it doesn't work . what i want is when i click on a table row, a textarea should appear containing >all informations[web page][1] . *this is the twig file: 1. the script

<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>
  1. the table row which should be selected
<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>
  1. the div where the details should appear
<div id="zoneDetail" style="margin-right: 20em">

    </div>

**this is the function in the controller:

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);
}

***the routing for the Ajax Function:

recDetailAjax:
path:     /recDetailAjax
defaults: { _controller: RandoPlusRandoBundle:Reclamation:afficherDetails }

****and finally the twig used by Ajax to load details:

<label>Description</label></br><textarea>Date : {{ detail.dateReclamation }}</br>type:{{ detail.typereclamation }}</br>Sujet:{{ detail.sujetreclamation }}</br>Message:{{ detail.message }}</textarea>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Android URL如何转成视频/音频,可行吗?
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题