我想產生一個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