iFrame的信息传递给Ajax和触发在阿贾克斯提交按钮 [英] iFrame passing information to Ajax and triggering the submit button in the Ajax
本文介绍了iFrame的信息传递给Ajax和触发在阿贾克斯提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,即阿贾克斯不触发尊重事件。
I'm having a problem where the Ajax is not triggering the respected event.
我有两种形式,一种可见的和一个隐藏的。
I have two forms, one visible and one hidden.
- 在可见形式中,用户可以输入一个电子邮件地址。
- 当用户点击可见表单的提交按钮,默认的提交是prevented,并通过Ajax的电子邮件进行了验证。
- 如果电子邮件地址无效,将出现一个错误消息。
- 如果电子邮件地址是有效的,隐藏表单的提交按钮应该使用JS(在阿贾克斯佳绩功能)点击。
下面是更多的code,以供参考:
Here is more code for reference:
可见的形式 的
<form accept-charset="utf-8" id="contactForm1" style="margin-top:;" action="https://app.getresponse.com/add_contact_webform.html?u=IzDa" 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:0px;" />
<br />
<input type="submit" class="wf-button" name="submit1" value=" " style="display:inline !important; margin-top:-10px !important;" />
</form>
隐藏的表单 的
<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="submitaw" 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>
JS的
阿贾克斯可见的形式 的
JS
Ajax for visible form
$('#contactForm1').click(function(e) {
e.preventDefault();
var email = $('#email').val();
var self = this;
$.ajax({
type: 'POST',
dataType: 'JSON',
url: 'check.php',
data: {
email: email
},
success: function (data) {
if (data.status == 'success') {
self.submit();
} else {
alert('The e-mail address entered is not valid.');
}
}
});
});
因此,这里是怎样的情况是:
So here's how the scenario would be:
- 在用户输入电子邮件地址,然后点击提交按钮。
- 的Ajax调用检查它是否是一个有效的电子邮件。
- 如果电子邮件是有效的,可见表 - 阿贾克斯成功函数
- 先设置隐藏表 - 的电子邮件值
- ,然后触发隐藏的表单 的提交按钮
- User enters email address, and clicks the submit button.
- Ajax-call checks whether it's a valid email.
- If the email is valid, the Ajax success function of the visible form
- first sets the email value of the hidden form
- and then triggers the submit button of the hidden form
- first sets the email value of the hidden form
正如前面所说,第三步是不工作
推荐答案
使用完整的,而不是成功。
use complete instead success
$('#contactForm1').click(function(e) {
e.preventDefault();
var email = $('#email').val();
var self = this;
$.ajax({
type: 'POST',
dataType: 'JSON',
url: 'check.php',
data: {
email: email
},
complete: function(data) {
if (data.status == 'success') {
self.submit();
} else {
alert('The e-mail address entered is not valid.');
}
}
});
});
这篇关于iFrame的信息传递给Ajax和触发在阿贾克斯提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文