3

我有以下 link_to 方法:

link_to "", votes_path(vote: { post_id: post.id, up: true}), method: :post, remote: true

我试图拦截触发的 AJAX 调用来操纵 POST 参数。使用 GET 请求这很容易,因为参数存储在 data 下:

$('#my_link').bind('ajax:before', function() {
  $(this).data('params', { foo: 'bar' })
});

但对于 POST 请求,情况并非如此。有人可以告诉我 POST 参数的存储位置吗?

4

1 回答 1

0

没关系,我刚刚发现自己。

您所要做的就是从链接数组中的第一个对象中操作 href 属性:

$('#my_link').bind('ajax:before', function() {
  $(this).first().attr('href', href + "&vote[custom_param]=customvalue");
});
于 2013-11-04T12:31:01.640 回答