我想产生一个Ajax请求的路径,但我得到了以下错误:如何在Symfony2中使用Routing.generate生成路由?
Error: The route "profesor_edit" requires the parameter "id".
的代码如下:
$.ajax({
type: 'POST',
url: Routing.generate('verify_user'),
data: {name:name},
dataType: 'json',
success: function(response) {
if(response.data!=null){
$("#container").load(Routing.generate('user_edit'), { id: response.data }); //"response.data" contains the value returned by the ajax call is an id value
}
else{
$("#container").append("<span >It could not find the id</span>");
}
}
})
路由文件:
user_edit:
path: /{id}/edit
defaults: { _controller: "BackendBundle:User:edit" }
我想我会发送错误的参数,但这是我见过的唯一方法。我感谢您的帮助。
如果使用FOSRoutingBundle,其'Routing.generate( 'user_edit', resonase.data)'[doku](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md#generating-uris) – mador
嗨@dokumador,我试过你的解决方案,现在我得到以下错误:'操作数e'中的'TypeError:invalid'。你知道这是为什么吗? – Joseph
究竟是什么在'response.data'中?它必须是用户标识。 – mador