1

我有一个表单,我在其中收集表单数据,当我serializeArray()这个表单时,我有这个:

[
  {
    "name": "authenticity_token",
    "value": "HRjaGFRSqX6EqTYnyohQbc9g6P6RTsDgV3qizYuoh+E="
  },
  {
    "name": "test[form_meta][index]",
    "value": "0"
  },
  {
    "name": "test[form_meta][location]",
    "value": "http://localhost/static/test/password.html"
  },
  {
    "name": "test[form_meta][title]",
    "value": "Passwords Form"
  },
  {
    "name": "test[form_meta][id]",
    "value": "form1"
  },
  {
    "name": "test[data][email[]]",
    "value": "arnel@personal.com"
  },
  {
    "name": "test[field_meta][email[]]",
    "value": "test.place_detail_email"
  },
  {
    "name": "test[data][password[]]",
    "value": "test"
  },
  {
    "name": "test[field_meta][password[]]",
    "value": "test.alarm_password"
  },
  {
    "name": "test[type][email[]]",
    "value": "text"
  },
  {
    "name": "test[label][email[]]",
    "value": "Email Address:"
  },
  {
    "name": "test[type][password[]]",
    "value": "text"
  },
  {
    "name": "test[label][password[]]",
    "value": "Password:"
  },
  {
    "name": "rec[email[]]",
    "value": "test.previous_address_category"
  },
  {
    "name": "rec[password[]]",
    "value": "c_test.password[]"
  }
]

还行吧。但是当我像这样将它发送到我的控制器时:

$.ajax({
    type: "post",
    data: data,
    success: function(){<code>},
    error: function(){<code>}
});

我在我的控制器上得到了这个:

{
  "authenticity_token"=>"HRjaGFRSqX6EqTYnyohQbc9g6P6RTsDgV3qizYuoh+E=",
  "test"=>{
    "form_meta"=>{
      "index"=>"0",
      "location"=>"http://localhost/static/test/password.html",
      "title"=>"Passwords Form",
      "id"=>"form1"
    },
    "data"=>{
      "email"=>[
        nil
      ],
      "password"=>[
        nil
      ]
    },
    "field_meta"=>{
      "email"=>[
        nil
      ],
      "password"=>[
        nil
      ]
    },
    "type"=>{
      "email"=>[
        nil
      ],
      "password"=>[
        nil
      ]
    },
    "label"=>{
      "email"=>[
        nil
      ],
      "password"=>[
        nil
      ]
    }
  },
  "rec"=>{
    "email"=>[
      nil
    ],
    "password"=>[
      nil
    ]
  },
  "controller"=>"test",
  "action"=>"create"
}

[nil]数组在这里杀死了我。我能做什么不必更改表单并获取实际输入的值而不是[nil]值。

这个问题有什么解决办法吗

4

0 回答 0