-1

我的问题很简单:当使用 Symfony 2 和 jQuery.post 时,我应该在路由中包含参数还是发布到静态 url 并在请求正文中发送参数?

$.post('/article/delete/5', function(e){
    // Do something
});

或者:

$.post('/article/delete', { id : 5 }, function(e){
    // Do something
});
4

1 回答 1

1

The former, if you look at a RESTful API the resource ID is always included in the URI if you want to get (GET), update (PUT), delta update (PATCH) or delete it (DELETE). In an ideal world however you would make a DELETE request using jQuery.

$.ajax('/article/delete/5', {
    'type': 'DELETE'
});

See: http://api.jquery.com/jQuery.ajax/

于 2013-01-08T23:42:26.803 回答