i am trying to use ajax with symfony 2 but i get the error 500, for my url i am using jsrouterbundle her's my route:

我正在尝试使用ajax与symfony 2,但我得到错误500,为我的网址我使用jsrouterbundle她的我的路线:

      vote:
           pattern:     /vote
           defaults:  { _controller: UserBundle:User:vote}
           options:
           expose: true

and this is my js function:

这是我的js函数:

          function vote(res) {
             var path=Routing.generate('vote');
             alert(path);
             $.ajax({
                     method: "POST",
                     url: path,
                     data: {vote: "Positif", id:res}
             })
             .done(function (msg) {
                    alert("Data Saved: " + msg);
              });
          }

and this where i call that function

这就是我称之为该功能的地方

        <img alt="test" onclick='vote("{{ result.id }}")'/>

her's my php controller

她是我的php控制器

           public function voteAction(Request $request)
{

    if ($request->isXmlHttpRequest()) {
        $vote= $request->get("vote");
        $id= $request->get("id");
        $em = $this->getDoctrine()->getEntityManager();
        $rep = $em->getRepository('LoginBundle:Resultat');
        $resultat = $rep->findOneBy($id);
        if ($resultat) {
            $resultat->setVote($vote);
            $em->flush();
        }
        return $this->render('LoginBundle:Login:inscription.html.twig');
    }

    return $this->render('LoginBundle:Login:inscription.html.twig');
}

i guess the problem is the route but i don't know to resolve this

我想问题是路线,但我不知道解决这个问题

thanks for your help

谢谢你的帮助

2 个解决方案

#1


Change the your JavaScript function path line

更改您的JavaScript函数路径行

var path=Routing.generate('vote'); 

To following

var path="Routing.generate('vote')";

更多相关文章

  1. jQuery: 刨根问底 attr and prop两个函数的区别
  2. jQuery ajax问题 - 无法让我的函数工作
  3. 通过调用返回参数的本地函数来构建Ajax Data部分
  4. Jquery ajax回调函数不执行
  5. JQUERY组装对象并调用自身函数改变自己的属性
  6. Angular ng-show不会根据函数返回值显示/隐藏
  7. 未捕获的ReferenceError:函数未定义,它标记
  8. 我怎么能用javascript编写这个简短的函数?
  9. 你能告诉为什么javascript函数没有在profile.php的提交按钮中执

随机推荐

  1. Android之底部導航欄--RadioGroup、TabHo
  2. Android 异步网络请求框架-Volley
  3. Android Compatibility Package
  4. Android中Timer使用示例
  5. Android之Activity的生命周期和Activity
  6. Android的bitmap和优化
  7. Android编译环境——ubuntu12.04上androi
  8. Native+WebApp中Phonegap调用Android Act
  9. eclipse中出现Could not find *.apk的问
  10. Android的Html类分析与扩展