[英]How to show 'Please wait' GIF image on Ajax load
Am using Ajax to send a request to a web server, but will like to show user with a GIF image indicating them to wait till the request is completed. 我正在使用Ajax将请求发送到Web服务器,但是希望向用户显示GIF图像,指示他们等待直到请求完成。
Can you please help me modify this code to load GIF image on sending the request. 您能否帮我修改此代码,以便在发送请求时加载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)
}
}
});
}
});
You can add ajaxStart
and ajaxEnd
handlers and can show your loading image like this: 您可以添加
ajaxStart
和ajaxEnd
处理程序,并可以显示加载图像,如下所示:
$(document)
.ajaxStart(function() {
$(Some Image).show();
})
.ajaxStop(function() {
$(Some Image).hide();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.