First. All is working, but i your tips for the projekt.
I create many projects with Symfony2 and there everywhere i use ajax, mostly with query.
Here is my routing.yml
_ajax:
path: /_ajax
defaults: { _controller: AcmeAllgemeinBundle:Default:ajax }
Here the call in the js
function checkStatus()
{
var url = $("#ajaxurl").data("url");
var postData = [
{ "id":"1", "name":"bob"},
{ "id":"2", "name":"jonas"}
]
$.ajax({
type: "POST",
data: postData,
url: url,
dataType: "json"
}).done( function(resp) {
console.log("mit done " + resp.text);
}).fail( function(){
console.log("Fehler");
});
}
But here is the question:
Should i handle evey ajax with one route and set one variable and call the functions by name in the controller like
{"job":"saveAdress"}
or should I create different route's for every job like
_ajax_saveAdress:
path: /_ajax/saveAdress
defaults: { _controller: AcmeAllgmeinBundle:Default:ajaxSaveJob }