我在this issue中阅读了jquery-rails,因为我想在发送之前向表单添加一些数据。
说明似乎很简单:挂钩before:send
并按照您的意愿行事。我是这样做的:
form.live "ajax:before", () ->
form.data('params', sortableList.nestedSortable('serialize'))
console.log "data we're sending along: " + form.data('params') # here I see the data I want to append to the form
POST
虽然不包含我添加到data-params
的任何数据:
Started POST "/admin/site/nav_items/render_event_response?source=menu_item_tree&type=submit" for 127.0.0.1 at 2011-09-29 20:48:11 +0800
Processing by Admin::Site::NavItemsController#render_event_response as JS
Parameters: {"authenticity_token"=>"sV8eEMpIVicbmT0nAfDdChgpRMyI5yR/N6m5VLk3+/Q=", "source"=>"menu_item_tree", "type"=>"submit"}
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
...snip...
我理解that issue错了吗? 如何在发送数据之前将数据附加到表单?
谢谢!
答案 0 :(得分:0)
你错过了关键部分。 ajax:before
回调接受3个参数,其中一个参数应该进行编辑。
你的代码应该是这样的(可能......我还没有测试过它)
form.live "ajax:before", (event,xhr,settings) ->
settings.data('params', sortableList.nestedSortable('serialize'))