简体   繁体   English

如何通过序列化表单数据发送数据

[英]how to send data through serialize form data

how to send a data for a multiple forms in a page a store a value of particular form through serialize form data. 如何在页面中发送多个表单的数据,如何通过序列化表单数据来存储特定表单的值。

$(function () {
    $('.form').on('submit', function (e) {
    console.log($(".form").serialize( )) ;
        $.post({
        type: 'post',
        url: 'admin/sv_replycomment.php',
        data: $(this).serialize(),
            success: function (data) {
                $('.form').trigger("reset"); 
                $('#rep_response').html(data);
                }
            });
        e.preventDefault();
        });
    }); 

This is due to your all forms may have same class="form" 这是由于您的所有表格可能具有相同的class="form"

So to submit only one form with serialized data, you need to give a unique id to the form you want to submit and serialize() data 因此,仅提交一个带有序列化数据的表单,您需要为要提交的表单和serialize()数据提供唯一的ID

For example: 例如:

<form id="type1" class="form">
...
</form>

And now your request should be like 现在您的要求应该像

$(function () {
    $('#type1').on('submit', function (e) {
        $.post({
            type: 'post',
            url: 'admin/sv_replycomment.php',
            data: $(this).serialize(),
            success: function (data) {
                $('#type1').trigger("reset"); 
                $('#rep_response').html(data);
            }
        });
        e.preventDefault();
        });
    }); 

I think this will solve your problem because using class selector will work for all form which have same class 我认为这将解决您的问题,因为使用类选择器将适用于所有具有相同类的表单

Modify your Code To post all fields data from the FORM to PHP 修改代码以将所有字段数据从FORM发布到PHP

//Ajmal Praveen
    $("#submit").click(function() {
        $.ajax({
            data: $("form").serialize(),
            ...rest
        });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM