0

行を削除するこのjavascript関数がありますが、関数が機能していません

$(document).ready(function()
{
    $('table#example td a.delete').click(function()
    {
        if (confirm("Are you sure you want to delete this row?"))
        {
            var id = $(this).parent().parent().attr('id');
            var data = 'id=' + id ;
            var parent = $(this).parent().parent();

            $.ajax(
            {
                   type: "POST",
                   url: "supprimerkpi",
                   data: data,
                   cache: false,

                   success: function()
                   {
                        parent.fadeOut('slow', function() {$(this).remove();});

                        // sets specified color for every odd row
                        $('table#example tr:odd').css('background',' #FFFFFF');
                   }
             });
        }
    });

そして私のページのhtml:

<a href="#" class="delete" style="color:#FF0000;">

私のコントローラーで

$repository = $this->getDoctrine()->getEntityManager()->getRepository('AdminBlogBundle:Condkpi'); $id=$this->getRequest()->query->get('id');
$em = $this->getDoctrine()->getEntityManager();
$uti=$repository->findOneBy(array('id' => $id));
$em->remove($uti);
$em->flush();
4

2 に答える 2

0

POSTメソッドを介して「id」を送信しています。したがって、次のように変更する必要があります。

$id=$this->getRequest()->query->get('id');

の中へ:

$id=$this->getRequest()->request->get('id');

また、次のように変更できます。

$uti=$repository->findOneBy(array('id' => $id));

の中へ:

$uti=$repository->find($id);

..find()主キーを使用してエンティティを検索する...

ちなみに「supprimerkpi」って何?それは有効なリンク先 URL ではありませんよね? :)

于 2012-10-24T21:21:35.950 に答える
0

あなたのrouting.yml

delete_data:
    path:     /delete
    defaults: { _controller: AcmeDemoBundle:Default:delete}

あなたのajax呼び出しのURLパラメータで、これに従ってそれを変更してください

var id = $(this).parent().parent().attr('id');

var data = 'id=' + id ;


 var parent = $(this).parent().parent();

        $.ajax(
        {
               type: "POST",
               url: "{{ path('delete_data') }}",
               data: {id :id },
               cache: false,

               success: function()
               {
                    parent.fadeOut('slow', function() {$(this).remove();});

                    // sets specified color for every odd row
                    $('table#example tr:odd').css('background',' #FFFFFF');
               }
         });

あなたのAcmeDemoBundle/Controller/DeafultControlller.php

public function deleteAction(Request $request)
{
   $id = $request->get('id');
   $repository = 
    $this->getDoctrine()->getEntityManager()->getRepository('AdminBlogBundle:Condkpi'); 
   $em = $this->getDoctrine()->getEntityManager();
   $uti=$repository->findOneById($id);
   $em->remove($uti);
   $em->flush();
}
于 2014-09-27T07:42:51.363 に答える