douzao2992 2014-10-01 04:25
浏览 128

使用带有Ajax的提交按钮提交两个表单

Explanation :

Here's the situation goes . I'm searching a way to call another Ajax function when the data is success but I'm unable to do due to unknown circumstances.

Code:

---HTML Form :

<form accept-charset="utf-8"  id="contactForm1" style="margin-top:;" action="" method="post">
    <input class="wf-input wf-req wf-valid__email" type="text" name="email"
         data-placeholder="yes" id="email" value="Enter Your Email Here" onfocus=" 
         if (this.value == 'Enter Your Email Here') 
         { this.value = ''; }" onblur="if (this.value == '') 
         { this.value='Enter Your Email Here';} " style="margin-top:;">
    </input>
    <br />
    <input type="submit" class="wf-button" name="submit1" value=" " style="display:  inline !important; margin-top:-10px !important;"></input>
</form>

----Ajax Code :

$(function() {
    $('.wf-button').click(function (e) {
    e.preventDefault();
    var email = $('#email').val();
    var frm = this;
    $.ajax({
        type: 'POST',
        dataType: 'JSON',
        url: 'check.php',
        data: {
            email: email
        },
        success: function (data) {
            if (data.status == 'success') {
            // Need to place it here
            frm.submit();
            } else {
                alert('The e-mail address entered is not valid.');
            }
        }
    });
});

---Another form with HTML in the same page:-

    <form method="post" id ="aweber" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl"  >
<div style="display: none;">
<input type="hidden" name="meta_web_form_id" value="947846900" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="awlist3599001" />
<input type="hidden" name="redirect" value="http://www.aweber.com/thankyou.htm?m=default" id="redirect_37ecf313df3b6f27b92c34c2c00ef203" />

<input type="hidden" name="meta_adtracking" value="ibb_test" />
<input type="hidden" name="meta_message" value="1" />
<input type="hidden" name="meta_required" value="email" />

<input type="hidden" name="meta_tooltip" value="" />
</div>
<div id="af-form-947846900" class="af-form"><div id="af-body-947846900"  class="af-body af-standards">
<div class="af-element">
<label class="previewLabel" for="awf_field-66127140">Email: </label>
<div class="af-textWrap"><input class="text" id="awf_field-66127140" type="text" name="email" value=""  />
</div><div class="af-clear"></div>
</div>
<div class="af-element buttonContainer">
<<input name="submitaw" id="submitaw" class="wf-button" type="submit" value="Submit" tabindex="501" />
<div class="af-clear"></div>
</div>
</div>
</div>
<div style="display: none;"><img src="http://forms.aweber.com/form/displays.htm?id=nCzsHCxsnAwM" alt="" /></div>
</form>

Scenarion :

I would when the Ajax trigger when the user click the submit button for the ID ContactForm1.
Before submitting the form , I want the Ajax to send the same value to the other form in the same page and click submit .

How?

  • 写回答

2条回答 默认 最新

  • duanshan1977 2014-10-01 04:42
    关注

    try this:

    $('#aweber').submit(function (e) {
        e.preventDefault();
        var email = $('#email').val();
        var frm = this;
        $.ajax({
            type: 'POST',
            dataType: 'JSON',
            url: 'check.php',
            data: {
                email: email
            },
            success: function (data) {alert('first form submitted');
                if (data.status == 'success') {
                    frm.submit();
                } else {
                    alert('The e-mail address entered is not valid.');
                }
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图