I use Symfony 3 and I try to call my function in the Default Controller with Ajax like this:
$(document).ready(function() {
$.ajax({
dataType: "json",
type: "POST",
data: {
action: 'active'
},
url: '{{ path ('
show_chat ')}}',
success: function(active) {
if (active === true)
$('.message-box').fadeIn();
},
error: function() {
console.log('error');
return false;
}
});
});
In the Default Controller I want to return a twig template and a variable which is true so my window for the chat can appear:
return $this->render('ChatBundle:Default:chat.html.twig',$online);
I use $presence = $request->get('active');
Symfony\Component\HttpFoundation\Response;
My method is POST but when I dump $request the method is GET. I do not understand what I am doing wrong and why it doesn't work ... Any ideas, please
Routing:
show_chat:
path: /chat
defaults: { _controller: slackChatBundle:Default:chat}
methods: [POST,GET]
If I put only POST method ,I have a message "No route found,Method Not Allowed (Allow: POST)
this is the dump of request: