【问题标题】:Posting additional data alongside serialized form data在序列化表单数据旁边发布附加数据
【发布时间】:2013-06-11 07:11:06
【问题描述】:

我想在从用户表单输入中获得的序列化数据旁边发布一些附加数据。

例如,

$.post('update.php', $("#theform").serialize(),{cposition:swidget}, function(data) {

});

这不会发布额外的帖子。我应该如何发布额外的数据?

【问题讨论】:

标签: jquery


【解决方案1】:

jQuery serialize 函数以&key=value 格式生成其值。它在内部使用$.param 执行此操作。您将能够以相同的方式附加您自己的值:

$.post('update.php', [$('#theform').serialize(), $.param({cposition:swidget})].join('&'), function(data) { ... });

【讨论】:

    【解决方案2】:

    你可以这样做:

    var data = $('#theform').serializeArray();
    data.push({cposition: swidget});
    //then
    $.post('update.php', data, function(data) {
    
    });
    

    【讨论】:

      【解决方案3】:

      您可以在序列化字符串的末尾附加一些内容。

      $.post('update.php', $("#theform").serialize() + '&cposition:swidget', function(data) {
      
      });
      

      【讨论】:

        猜你喜欢
        • 2016-03-16
        • 1970-01-01
        • 2016-11-09
        • 2022-10-30
        • 2018-05-04
        • 1970-01-01
        • 1970-01-01
        • 2014-03-13
        • 1970-01-01
        相关资源
        最近更新 更多