2

我确实<input>在页面上生成了一些带有随机名称的 s(一次近十个)。

卡在关于提交它们的问题上。

我使用此代码提交:

$('.table_data').submit(function(event)
{
    event.preventDefault();
    // some validation check and then

    $.post(url, {user_mail: mail}, function()
    {
        alert('done);
    });
});

问题是,它只提交user_mail

如何提交所有<input>s的数据?

尝试使用$.post(url, function(){}),它什么也没发送。

可以将所有输入放入数组中,然后扔给$.post函数,但我不确定如何做好。

4

3 回答 3

6

如果您的表单的类名是table_data然后使用这个

$.post(url,$('.table_data').serialize(), function(){})

您将获得表单输入names作为global POST数组的键。

完整代码

$('.table_data').submit(function(event)
{
    event.preventDefault();
    // some validation check and then

    $.post(url, $(this).serialize(), function()
    {
        alert('done');
    });
});

阅读更多关于$.serialize

于 2012-06-03T18:48:07.450 回答
1
$.post(
   url,                  // url to submit
   $(this).serialize(),  // make a standard-looking query string using all inputs value
   function(response) {        
     // success function
     // in parameter response is to capture data send from capture
  },
  'json'  // dataTyep in which format you're accepting 
          // data from server may be html, xml ans so on
);

相关参考:

于 2012-06-03T18:54:07.487 回答
0

您正在使用 ajax 阻止表单提交的默认行为event.preventDefault(),然后仅将 usermail 值发送到服务器。

据我了解,您需要对表单进行序列化,以便获取所有名称及其值,然后将其发送到服务器。为此,您需要jQuery 中的序列化函数

于 2012-06-03T18:51:12.427 回答