【问题标题】:Rails 3.1, jQuery: Append data to a form before sending it outRails 3.1,jQuery:在发送数据之前将数据附加到表单
【发布时间】:2011-11-27 16:51:18
【问题描述】:

我在jquery-rails 中阅读了this issue,因为我想在发送之前向表单添加一些数据。

说明看起来很简单:连接到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如何在发送之前将数据附加到表单?

谢谢!

【问题讨论】:

  • 在那里变得相当困惑,直到我意识到涉及到咖啡脚本......

标签: ruby-on-rails jquery coffeescript


【解决方案1】:

issue you are refering to

您错过了关键部分。 ajax:before callback 接受 3 个参数,你应该编辑其中一个参数。

你的代码应该是这样的(可能......我还没有测试过)

form.live "ajax:before", (event,xhr,settings) ->
  settings.data('params', sortableList.nestedSortable('serialize'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-18
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    相关资源
    最近更新 更多