0

I'm trying to generate a path in an Ajax request, but I get the following error:

Error: The route "profesor_edit" requires the parameter "id".

The code is as follows:

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

routing file:

user_edit:
     path:     /{id}/edit
     defaults: { _controller: "BackendBundle:User:edit" }

I think I will be sending the wrong parameter, but it's the only way I've ever seen. I appreciate your help.

4
  • 1
    if you use FOSRoutingBundle, its Routing.generate('user_edit', resonse.data) doku Commented Feb 12, 2016 at 12:19
  • Hi @dokumador, I tried your solution and now I get the following error: TypeError: invalid 'in' operand e. Would you know why that is? Commented Feb 12, 2016 at 12:41
  • what is in response.data exactly? it must be the user id. Commented Feb 12, 2016 at 12:46
  • Hi @mador, That contains a user id that is returned in the ajax call in the parameter "data" in this way: return new JsonResponse(array('data' =>$user->getId()), 200); Commented Feb 12, 2016 at 12:48

1 Answer 1

3

Assuming you are using FOSJSRoutingBundle, use the following :

$("#container").load(Routing.generate('user_edit', { id: response.data }));
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @chalasr, thanks for your answer, right now I had come to the same solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.