需要帮助,2提交表格1 ajax发送帖子到1 file.php

时间:2015-09-07 08:18:34

标签: javascript jquery ajax

你好我需要使用单个ajax或jquery发布2个表单到1个通用文件,我的代码就是这个

<form id="filter-group1" class="form" target="remember" autocomplete="on" method="post">
    <input pattern="[0-9]*" value="" name="ch1" maxlength="10" size="10" autofocus="" autocorrect="off" id="client-nbr" class="form-control numeric" rv-value-reactive="form.idTelematique" type="tel">
    <a class="reset-input" href="#" id="initClient" onclick="change()"></a>
    <input value="" id="memoriser" name="memoriser" type="checkbox">
    <button type="submit" id="remember_button" class="hidden"></button>
</form>

<form id="filter-group2" method="post" class="form">
    <div class="field-password">
        <input  rv-value="form.password | starPassword" readonly="" maxlength="6" name="staredPassword" id="secret-nbr" class="form-control" type="password">
        <a class="reset-input" href="#" id="initPass" onclick="change1()"></a>
    </div>
</form>

<div class="cell-password">
    <div class="field-valid">
        <button type="button" href="#" class="btn-primary btn-block" onclick="filterBy()" id="submitIdent" rv-text="config.app.identification.boutonTitle" >submit</button>
    </div>
</div> 

JS

function filterBy() { 
    // Construct data string 
    var dataString = $("#filter-group1, #filter-group2").serialize(); 
    // Log in console so you can see the final serialized data sent to AJAX 
    console.log(dataString); 
    // Do AJAX 
    $.ajax( { 
        type: 'POST', 
        url: 'filter.php', 
        data: dataString, 
        success: function(data) { 
            console.log(data);
            $('#message').html(data);
        } 
    }); 
} 

<button type="button"需要使用ajax提交2个表单以在单个文件中发布php

问题没有解决,如果你不能,当我尝试clik on <button type="button" href="#" class="btn-primary btn-block" onclick="filterBy()"函数不执行时,让我成为一个完整的脚本

1 个答案:

答案 0 :(得分:0)

更改以创建数据字符串:

var dataString = {
                   frm1 : $("#filter-group1").serialize(),
                   frm2 : $("#filter-group2").serialize()
                 };

在php结束时,您可以使用键frm1, frm2获取值。