duandeng2011 2016-05-20 12:10
浏览 20

具有输入sf2的Ajax更新实体

I ask you because I am stuck on a problem (I have previously searched).

I would like, from an input field, update the database without the user noticing.

My code :

<script>
        function updateResult(str, idg, idt) {
            if (str.length == 0)
                return;
            else
//                alert("data : " + str + "; id_game : " + idg + "; id_team : " + idt);

                $.ajax({
                        url: Routing.generate('basket_admin_tournament_update', { "game_id": idg, "team_id": idt, "score": str}),
                        type: "POST"
                        data: { game_id : idg, team_id: idt, score: str },
                        success: function(data) {
                                alert('ok');
                        },
                        error: function() {
                                alert('error');
                        }
                });

        }
    </script>

PHP

// revoir les espaces dans les noms des tournois
    /**
     * @ParamConverter("tournament", options={"mapping": {"tournament_name": "name"}})
     */
    public function showAction(Tournament $tournament) {
        return $this->render('BasketTournamentBundle:Tournament:show.html.twig', array(
                    'tournament' => $tournament
        ));
    }

    public function updateAction($game_id, $team_id, $score) {
        $em = $this->getDoctrine()->getManager('tournament');

        $game = $em
                ->getRepository('BasketTournamentBundle:Tournament')
                ->findOneBy($game_id);

        if ($team_id == $game->getTeam1()) {
                $game->setScoreTeam1($score);
                $em->persist($game);
                $em->flush();
        } else {
                $game->setScoreTeam2($score);
                $em->persist($game);
                $em->flush();
        }

        return new Response();
    }


    <h3>Planning</h3>
{% for game in step.games %}
  {% if (game.team1 in pool.teams) or (game.team2 in pool.teams) %}
    <p>{{ game.dateGame|date('h:m:s') }} : {{ game.team1.name }} <input type="text"   onblur="updateResult(this.value, {{ game.id }}, {{ game.team1.id }})"> - <input type="text" onblur="updateResult(this.value, {{ game.id }}, {{ game.team2.id }})"> {{ game.team2.name }}</p>
  {% endif %}
{% endfor %}

I get my data well in the alert.

I can not update my entity..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用