相关疑难解决方法(0)

Ajax网址不起作用+ Symfony2

我想用jquery autocomplete进行ajax调用,如下所示:

$("#register_player_team").autocomplete({
    source: function( request, response ) {
        $.ajax({
            url: "{{path('volley_scout_getteams_data')}}",
            dataType: "jsonp",
            success: function( data ) {
                console.log(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(xhr.status);
                console.log(thrownError);
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

在我的routing.yml中,我定义了以下路由:

volley_scout_getteams_data:
pattern:  /team/getteams
defaults: { _controller: VolleyScoutBundle:Team:getteams }
Run Code Online (Sandbox Code Playgroud)

在我的TeamController中,我有一个名为getteamsAction()的动作:

public function getteamsAction()
{
    $entityManager = $this->getDoctrine()->getManager();
    // Get teams from database
    $teams = $entityManager->getRepository('VolleyScoutBundle:Teams')->findAll();

    foreach($teams as $team){
        var_dump($team);
    }

    die();
}
Run Code Online (Sandbox Code Playgroud)

(dump和die()仅用于测试,我想检查他是否可以找到链接).但是当我想进行ajax调用时,我总是会收到以下错误:

http://localhost:8080/volleyscout/web/app_dev.php/user/%7B%7Bpath('volley_s…)%7D%7D?callback=jQuery110207641139030456543_1389372448462&_=1389372448463 404 (Not Found) 
Run Code Online (Sandbox Code Playgroud)

由于某种原因,他无法找到行动......有人知道我做错了什么吗?当我尝试这样的链接时:web/app_dev.php/team/getteams我得到了团队的转储..

更新: 我的javascript链接在基本视图(twig)中定义,如下所示:

{% block javascripts %}
    {% …
Run Code Online (Sandbox Code Playgroud)

php ajax jquery symfony

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

jquery ×1

php ×1

symfony ×1