Reputation: 70416
The ajax feature is on route http://mysite/playlist-edit/3
Javascript:
$("#applySort").click(function(){
var list = $("#sortable").sortable('toArray');
$.post({
type: 'POST',
url: " {{ path('save_sorting', { 'id' : customer.id}) }} ",
data: { "list" : JSON.stringify(list) },
success: function(data) {
alert("success");
}
});
return false;
});
Route:
save_sorting:
pattern: /save-sorting/{id}
defaults: { _controller: SomeApiBundle:Customer:applySorting}
requirements:
_method: POST
Controller action (empty):
private function applySortingAction($id){
}
Error:
POST http://mysite/playlist-edit/%5Bobject%20Object%5D
500 Internal Server Error
As you can see in the javascript code http://mysite/playlist-edit/%5Bobject%20Object%5D
is actually not the url in the javascript, it should be http://mysite/save-sorting/3
.
Jquery seems to call the wrong url.
Request-Header
Accept */*
Accept-Encoding gzip, deflate
Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Connection keep-alive
Cookie PHPSESSID=rkdre4frkoidgo3n1hsi4th7v5
DNT 1
Host gartenfernsehen
Referer http://mysite/playlist-edit/3
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
X-Requested-With XMLHttpRequest
Response-Header
Connection close
Content-Length 0
Content-Type text/html
Date Mon, 25 Jun 2012 06:21:07 GMT
Server Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By PHP/5.3.8
Any ideas why I get this error? I notices that http://mysite/playlist-edit/%5Bobject%20Object%5D
is actually wrong but I dont know how this is created.
Upvotes: 3
Views: 1801
Reputation: 70416
I did not expect this. But I changed $.post to $.ajax and now the right url is requested.
Upvotes: 1
Reputation: 8980
Your action method in your controller should be named:
public function applySortingAction($id){
}
$id
being the {id}
parameter of your save_sorting
route
Upvotes: 1