亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的控制器中的 JS 變量問題

我的控制器中的 JS 變量問題

UYOU 2021-06-23 17:08:06
在我的 symfony (v3.4) 項目中,我需要將一些 javascript 變量從我的視圖傳遞給我的控制器:我使用 Jquery 和 Ajax 將我的變量發送到控制器,但我無法訪問我的變量。我的 Ajax 請求沒有問題,我通過 Symfony 分析器進行了檢查,請求已正確發送,但由于某種原因,控制器甚至無法檢測到 Ajax 請求。這是我的控制器:public function saisieAction(Request $request)    {        $user = $this->getUser();        $thisyear = date("Y");        $em = $this->getDoctrine()->getManager();        // Create the form        $form = $this->get('form.factory')->createBuilder(FormType::class)            ->add('ndf', CollectionType::class, array(                'entry_type' => NoteDeFraisType::class,                'label' => false,                'allow_add' => true,                'allow_delete' => true,            ))            ->getForm();        // if the form has been submited        if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {            if($request->isXMLHttpRequest()){                //After some code debuging, this is never                 //executed                $month = $request->get('month');                $year = $request->get('year');                $sub_date = $month .'/' .$year;            }            $notesDeFrais = $form['ndf']->getData();            foreach ($notesDeFrais as $ndf) {                $ndf->setUser($user);                $ndf->setMonth($sub_date);                $em->persist($ndf);            }            $em->flush();        }        return $this->render('AvPlatformBundle:Platform:saisie.html.twig',            array(                'year' => $thisyear,  'form' => $form->createView()            ));    }我的 saisie.html.twig 視圖中的腳本:$(".month").click(function() {     var click = $(this);     var month = click.val();     var year = $("#years").val();      $.post("{{ path('avaliance_platform_saisie') }}",            { 'month' : month,              'year' : year            },            function (data,status) {                alert('Data sent');            });                    });
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號