我正在使用jquery/ajax/php登录到我的网站。当我将这个登录功能检查到我的服务器时,检查登录详细信息需要几秒钟的时间。所以我想在检查登录详细信息时显示加载图像。如何显示此加载图片?如何在脚本运行时显示加载图像?
这种加载图像我想用:
<img src="images/loading-image.gif"/>
表:
<div id="success"></div>
<form id="login_process">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Username</td>
<td><input type="text" name="front_username" placeholder="Username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="front_password" placeholder="Password"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="LogIn" class="submit"></td>
</tr>
<tr>
<td colspan="2">Forgot your password ? Click <a href="forgotpass.php">here.</a></td>
</tr>
</table>
</form>
jQuery代码:
<script>
$('#login_process').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'login_process.php',
data: $(this).serialize(),
dataType: 'json',
success: function (data) {
$('#success').html('');
$.each(data, function(key, value) {
if(key !== 'error') {
$('#success').append('<p>'+value+'</p>');
}
});
if(! data.error) {
$('#hide').hide();
setTimeout(function() {
$('input[type=submit]').attr('disabled', false);
window.location.href = "index.php";
}, 2000);
}
}
});
});
</script>
@MohitArora是当登录按钮被按下。 – creativeartbd 2014-11-03 04:42:46