我将如何使用jQuery ajaxstart和ajaxstop与$。员额? [英] How would I use jquery ajaxstart and ajaxstop with $.post?
本文介绍了我将如何使用jQuery ajaxstart和ajaxstop与$。员额?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我想显示加载GIF ...
这里的code我使用:
$(#信箱变更输入[类型=提交])。点击(函数(事件){
.post的$('user_settings.php',$(#信箱变)。序列化()函数(RES){
$(RES).insertBefore(灰色);
},HTML)
});
解决方案
$(#加载)。ajaxStart(函数(){
$(本).show();
})。ajaxStop(函数(){
$(本).hide();
});
编辑:
$(#信箱变更输入[类型=提交])。点击(函数(事件){
$(#加载)。显示()
.post的$('user_settings.php',$(#信箱变)。序列化()函数(RES){
$(RES).insertBefore(灰色);
$(#加载)隐藏()。
},HTML);
});
或
$。阿贾克斯({
网址:user_settings.php,
数据:$(#信箱变)序列化()。
beforeSend:函数(){
$(#加载)显示()。
},
完成:函数(){
$(#加载)隐藏()。
},
成功:函数(RES){
$(RES).insertBefore(灰色);
}
});
请参阅:
- http://api.jquery.com/ajaxStart/
- http://api.jquery.com/ajaxStop/
- http://docs.jquery.com/Ajax_Events
- <一个href="http://api.jquery.com/category/ajax/global-ajax-event-handlers/">http://api.jquery.com/category/ajax/global-ajax-event-handlers/
Basically I want to show a loading gif...
here's the code I'm using:
$("#mail-change input[type=submit]").click(function(event){
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
}, 'html')
});
解决方案
$("#loading").ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
EDIT:
$("#mail-change input[type=submit]").click(function(event){
$("#loading").show()
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
$("#loading").hide();
}, 'html');
});
or:
$.ajax({
url : 'user_settings.php',
data: $("#mail-change").serialize(),
beforeSend: function(){
$("#loading").show();
},
complete: function(){
$("#loading").hide();
},
success: function(res) {
$(res).insertBefore(".grey");
}
});
See:
- http://api.jquery.com/ajaxStart/
- http://api.jquery.com/ajaxStop/
- http://docs.jquery.com/Ajax_Events
- http://api.jquery.com/category/ajax/global-ajax-event-handlers/
这篇关于我将如何使用jQuery ajaxstart和ajaxstop与$。员额?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文