I am trying to generate the route for an Ajax call in my file.js
. I have installed FOSJsRoutingBundle
and followed the instruction. I exposed my route for the request but the Routing.generate()
method gives the error The route 'ajax' does not exist
. I tested the route with a button and it works.
The Javascript file
$('#add_assistant_next').click(function () {
var route = Routing.generate('ajax');
var that = $(this);
var i = $.ajax({
url: route,
type: "POST",
dataType: "json",
data: {"ajax-user": "test user string"},
async: true,
success: function (data) {
$('div#ajax-results').html(data.output);
}
});
return false;
});
The controller route
/**
* @Route(name="ajax", options={"expose" = true},
* methods={"GET", "POST"},
* path="/ajax")
*
*
*
*/
public function ajaxAction(Request $request)
{
dump('route called');
die();
if ($request->request->get('ajax-user')) {
dump('request recieved');
die();
}
}
You need to dump your routes every time you add new route https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html