我正在尝试让我的 jQuery 使用 CSS 动画/类更改并使用此登录论坛的 ajax 帖子。我在重新编写 JQuery 动画脚本并为用户名和密码合并 Ajax 端口时遇到问题。它似乎没有发布登录信息。<form class="login" action="" method="post" autocomplete="false"> <div class="group"> <input id="user" type="username" name="user" class="input" placeholder="Username" required autofocus> </div> <div class="group"> <input id="password" type="password" name="password" class="input" data-type="password" placeholder="Password" required> </div> <div class="group"> <button> <i class="spinner"></i> <span class="state">Log in</span> </button> </div> <div class="hr"></div></form>这是jQueryvar working = false;$('.login').on('submit', function(e) { e.preventDefault(); if (working) return; working = true; var $this = $(this), $state = $this.find('button > .state'); $this.addClass('loading'); $state.html('Authenticating'); $.ajax({ type: "POST", data: $(this).serialize(), cache: false, url: "login.php", success: function(data) { if (data.status == 'success') { this.addClass('ok'); $state.html('Welcome back!'); setTimeout(function() { window.location = "/index.php" }, 4000); } else if (data.status == 'error') { setTimeout(function() { $state.html('Log in'); $this.removeClass('ok loading'); }, 3000); } }, });});
1 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
在使用 Diego 的建议并将输出输出到控制台日志后,我能够确定 php 函数没有返回任何内容。添加带有相应结果的回声解决了我的问题,并在 if 语句中使用了“data”而不是“data.status”。
- 1 回答
- 0 关注
- 147 浏览
添加回答
举报
0/150
提交
取消