所以,我似乎有我的代码的一些问题。现在我刚开始学习AJAX和jQuery,所以我对它很感兴趣。他们的方式在现场的工作原理是:我的AJAX脚本将正常运行一次,但它不会再次运行
当用户点击登录按钮形式将他们输入用户名和密码的按钮下出现。当用户点击登录我的AJAX脚本将会处理记录他们,并刷新自己的形象,让他们知道他们正在登录。然后,当他们要注销他们点击注销和它记录出来没问题。
我遇到的问题是,一旦我通过登录/注销过程中,我无法得到的形式而无需刷新页面再次显示了运行。
我希望我是有道理= /这里是我的代码有:
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/jscript"></script>
<script>
$(function() {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'loginsystem/login.php',
data: $('form').serialize(),
success: function() {
$("#loginForm").slideUp('slow');
$("#playerFace").load('ajaxPHPScripts/getUserAvatar-100px.php');
$("#loginLogout").load('ajaxPHPScripts/loginLogoutButton.php');
}
});
e.preventDefault();
});
});
function doSomething() {
$.ajax({
type: 'get',
url: 'loginsystem/logout.php',
success: function() {
$("#playerFace").load('ajaxPHPScripts/getUserAvatar-100px.php');
$("#loginLogout").load('ajaxPHPScripts/loginLogoutButton.php');
}
});
}
$(document).ready(function(){
$("#loginForm").hide();
$("#loginbtn").click(function(){
$("#loginForm").slideToggle('slow');
});
});
$(document).ready(function() {
$("#removeLoginForm").click(function(){
$("#loginForm").slideUp('slow');
});
});
</script>
现在的HTML:
<div id="sidebar">
<div id="sidebarinner">
<div id="sidebarInnerInner">
<div id="playerAvatar">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="width:100px;" id="playerFace"><img src="https://minotar.net/avatar/steve/100"></td>
<td style="text-align:center;"><?php ServerPing(); //pings to see if server is online?></td>
</tr>
</table>
</div>
<div id="joinAndLog">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="text-align:center; height:100%;">
<tr>
<td style="width:50%;" id="loginLogout"><?php LoginOrLogout(); ?></td>
<td style="width:50%;"><?php SignupOrManageAcc(); ?></td>
</tr>
</table>
</div>
<div id="loginForm">
<form class="sideForm" id="testform" style="text-align:center; margin-bottom:10px;">
<input type="text" id="name" name="username" value="" placeholder="Username..."/>
<br />
<input type="password" id="pass" name="password" value="" placeholder="Password..."/>
<br />
<input id="submit" type="submit" name="submit" value="Login" style="width:25%; cursor:pointer;" />
<input type="reset" name="" value="Cancle" id="removeLoginForm" style="width:25%; cursor:pointer;" />
<br />
<!--a href="#" style="padding:0px; margin:0px;">Forgot Password</a-->
</form>
</div>
</div>
将这个只能拿到形式,一旦它再次打乱了之前的工作?或者它会保持表单的工作?我也会给它一个尝试,但标识只是想听听你有什么要说=) –
这应该是你的成功的功能里面,这样一种新的形式是,它必将载入每次。你可能想要在其他地方定义这个函数btw ...我将编辑我的答案,详细说明我的意思。 –
Ohhhh这很有道理!非常感谢你!所以基本上它会是一个循环?只是不使用任何时间,为或做 –