![](/img/trans.png)
[英]how to show loading GIF image or "please wait" message before printing large PDF file in JavaScript
[英]How to show 'Please wait' GIF image on Ajax load
我正在使用Ajax將請求發送到Web服務器,但是希望向用戶顯示GIF圖像,指示他們等待直到請求完成。
您能否幫我修改此代碼,以便在發送請求時加載GIF圖片。
jQuery(document).submit(function(e){
var create_acct_form = jQuery(e.target);
if(create_acct_form .is("#createacctform")){ // check if this is the form that you want (delete this check to apply this to all forms)
e.preventDefault();
jQuery.ajax({
type: "POST",
url: create_acct_form .attr("action"),
data: create_acct_form .serialize(), // serializes the form's elements.
success: function(data) {
console.log(data);
if( data.status == 'error' ) {
// error handling, show data.message or what you want.
} else {
// same as above but with success
$("#createacctform")[0].reset();
$("#create_acct-info").html(data)
}
}
});
}
});
您可以添加ajaxStart
和ajaxEnd
處理程序,並可以顯示加載圖像,如下所示:
$(document)
.ajaxStart(function() {
$(Some Image).show();
})
.ajaxStop(function() {
$(Some Image).hide();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.