I'm trying to send a value into a path to a Symfony Controller vía Ajax. I am sure that I'm wrong in sending, but I can't find the error
Let me share the code:
View
I've written
<script type="text/javascript">
$("#my-select").change(function(event){
var id=$("#my-select").val();
var path = "path('go_to_route/" + id+ "')";
var route="{{ "+path+" }}";
alert(path);
$.ajax({
url : route,
data : {},
type : 'POST',
dataType : '',
success : function(data) {
alert(data);
},
error : function(xhr, status) {
alert('Error');
},
complete : function(xhr, status) {
//alert('Finally');
}
});
});
</script>
Routing
In routing.yml
go_to_route:
path: /my-route/{id}
defaults: { _controller: myBundle:MyController:myFunction }
This Action is in MyBundle/MyController
Controller
public function myFunctionAction($id){
return new Response($id);
}
Ajax always return "Error" message. I' think that the error happened while sending the value. I've tried, but it doesn't work. What am I doing wrong? This is my first week with Symfony. I'll be grateful for help.
alert(path);?