我正在使用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