$(this).serialize() — How to add a value?

前端 未结 8 2151
清酒与你
清酒与你 2020-12-02 08:41

currently I have the following:

$.ajax({
    type: \'POST\',
    url: this.action,
    data: $(this).serialize(),
});

This works fine, howe

相关标签:
8条回答
  • 2020-12-02 09:37

    We can do like:

    data = $form.serialize() + "&foo=bar";
    

    For example:

    var userData = localStorage.getItem("userFormSerializeData");
    var userId = localStorage.getItem("userId");
    
    $.ajax({
        type: "POST",
        url: postUrl,
        data: $(form).serialize() + "&" + userData + "&userId=" + userId,
        dataType: 'json',
        success: function (response) {
            //do something
        }
    });
    
    0 讨论(0)
  • 2020-12-02 09:38

    Add the item first and then serialize:

    $.ajax({
        type: 'POST',
        url: this.action,
        data: $.extend($(this), {'NonFormValue': NonFormValue}).serialize()
    });
    
    0 讨论(0)
提交回复
热议问题