Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在Symfony2中使用Routing.generate生成带参数的路由?_Jquery_Symfony - Fatal编程技术网

Jquery 如何在Symfony2中使用Routing.generate生成带参数的路由?

Jquery 如何在Symfony2中使用Routing.generate生成带参数的路由?,jquery,symfony,Jquery,Symfony,我试图在Ajax请求中生成路径,但出现以下错误: 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) { i

我试图在Ajax请求中生成路径,但出现以下错误:

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>");        
      }   
    } 
  })

我想我会发送错误的参数,但这是我见过的唯一方法。非常感谢您的帮助。

如果您使用的是FOSJSRoutingBundle,请使用以下命令:

$("#container").load(Routing.generate('user_edit', { id: response.data }));

假设您使用的是FOSJSRoutingBundle,请使用以下命令:

$("#container").load(Routing.generate('user_edit', { id: response.data }));

如果使用FOSRoutingBundle,则其
路由.generate('user_edit',resonse.data)
Hi@dokumador,我尝试了您的解决方案,现在我得到以下错误:
TypeError:invalid'in'operator e
。你知道为什么吗?确切地说,
响应中的数据是什么?它必须是用户id.Hi@mador,它包含在参数“data”的ajax调用中返回的用户id:
returnnewJSONResponse(array('data'=>$user->getId()),200)
如果使用FOSRoutingBundle,则其
路由.generate('user_edit',resonse.data)
Hi@dokumador,我尝试了您的解决方案,现在出现以下错误:
TypeError:invalid'in'operator e
。你知道为什么吗?确切地说,
响应中的数据是什么?它必须是用户id.Hi@mador,它包含在参数“data”的ajax调用中返回的用户id:
returnnewJSONResponse(array('data'=>$user->getId()),200)
Hi@chalasr,谢谢你的回答,现在我已经找到了相同的解决方案Hi@chalasr,谢谢你的回答,现在我找到了相同的解决方案