nasy
nasy

Reputation: 549

Ajax not reciving data. Symfony2

The idea is when i click on a button it calls sendeRequest() and the controller receives the petition. But I'm not receiving anything.

I wan't to send a request to the controller. (I have set a redirection in the controller, to check that I'm receiving the data). I've tried doing:

function sendRequest(){ 
 $.ajax({
   type: "POST",
   url:  "{{ path('login') }}" ,
   cache: "false",
   dataType: "html",
   success: function(result){ $("div#box").append(result);}
 }); 
}

And in the controller

$request = $this->getRequest();   
if($request->isXmlHttpRequest()){    
         return $this->render('mainBundle:Register:register.html.twig');
}

I'm using jquery 1.7.2

Upvotes: 1

Views: 310

Answers (1)

migueldiganchi
migueldiganchi

Reputation: 41

You can do this:

if($this->getRequest()->isXmlHttpRequest()){   
   return new Response(json_encode(array(
      'form'=>$this->render('mainBundle:Register:register.html.twig')->getContent()))
   );
}

Upvotes: 2

Related Questions