gpt4 book ai didi

php - 为什么我的 JS 代码在明显的循环中运行?

转载 作者:行者123 更新时间:2023-11-28 02:12:34 25 4
gpt4 key购买 nike

我有以下代码:

JS

<script type="text/javascript">
$(function(){
$('#fgotpwfield').hide();

$('#login_submit').click(function() {
$('#form_result').fadeOut('fast');
$('#myccrxlogin input').removeAttr('disabled');
$('#myccrxlogin').submit();
});

if ($("#myccrxlogin").length > 0) {
$("#myccrxlogin").validate({
rules: {
email: { required: true, email: true },
password: 'required'
},
messages: {
email: { required: 'Your email address is required.',
email: 'Please enter a valid email address.'},
password: 'Your password is required.'
},
submitHandler: function(form) {
$('#myccrxlogin input').attr('disabled','true');
$('#login_submit').fadeOut('fast');
$('#forgotpw').fadeOut('fast');
$('body').append('<div id="page_load"></div>');

var email = $("#email").val();
var pw = $("#password").val();
var data = 'email=' + email + '&password=' + pw;

$.ajax({
url: "hidden url",
type: "POST",
data: data,
cache: false,
success: function (html) {
$('#page_load').remove();

if(html == 'OK') {
alert(html);
} else {
//$("#password").val('');
$("#form_result").html(html);
$('#form_result').fadeIn('slow');
$('#myccrxlogin input').removeAttr('disabled');
$('#login_submit').fadeIn('slow');
$('#forgotpw').fadeIn('slow');
}
}
});
} /*close submit handler */
});
};
});
</script>

HTML

<div id="form_result" style="margin:10px; display:none;" class="field-submit-error"></div><div style="clear:both;"></div>
<div id="loginformfield">
<p style="font-size:24px; font-weight:bold; font-family:Arial, Helvetica, sans-serif; color:#f93;">Login</p>
<form class="loginform" id="myccrxlogin" method="post" target="_parent">
<p>
<input name="email" type="text" id="email" tabindex="1" />
<label for="email">E-mail</label></p>

<p><input name="password" type="password" class="text large required" id="password" tabindex="2" />
<label for="password">Password</label></p>

<div class="loading"></div>
<p><a href="#" id="forgotpw">I forgot my password</a></p>
<p><a class="readmore" href="#" id="login_submit" style="margin-bottom:0.5em;" tabindex="3">Login!</a></p>
</form>
</div>

一个人输入他们的电子邮件和密码,文件首先被验证然后通过 ajax 调用成功运行。 ajax PHP 页面回显错误或“正常”。我知道代码会“确定”,因为触发了 alert(html) 但它会无限运行。不确定为什么?

更新

我相信我可能遇到了此处描述的递归问题:http://docs.jquery.com/Plugins/Validation#General_Guidelines尽管我不确定它是否适用。

最佳答案

我无法单步执行,但我相信您需要让您的 submithandler 返回 false。

我相信表单是由表单操作和 ajax 提交提交的。

关于php - 为什么我的 JS 代码在明显的循环中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7438962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com