ajaxStart() 显示加载消息似乎不起作用
我用户 jquery.ajax 调用 asp.net mvc 的控制器...我想显示一个加载指示器..我尝试了这个,但这似乎不起作用...
<div class="loading" style="padding-left:5px; margin-bottom:5px;display:none;">
Loading... 
</div>
我的 jquery ajax 调用看起来像这样,
function getMaterials(currentPage) {
$.ajax({
url: "Materials/GetMaterials",
data: {'currentPage': (currentPage + 1) ,'pageSize':5},
contentType: "application/json; charset=utf-8",
global: false,
async: false,
dataType: "json",
success: function(data) {
var divs = '';
$("#ResultsDiv").empty();
$.each(data.Results, function() {
//my logic here....
$(".loading").bind("ajaxStart", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
});
}
});
return false;
}
我的加载指示器似乎没有显示..任何建议....
I user jquery.ajax call to controller of asp.net mvc... I would like to show a loading indicator.. I tried this but that doesn't seem to work...
<div class="loading" style="padding-left:5px; margin-bottom:5px;display:none;">
Loading... 
</div>
and my jquery ajax call looks like this,
function getMaterials(currentPage) {
$.ajax({
url: "Materials/GetMaterials",
data: {'currentPage': (currentPage + 1) ,'pageSize':5},
contentType: "application/json; charset=utf-8",
global: false,
async: false,
dataType: "json",
success: function(data) {
var divs = '';
$("#ResultsDiv").empty();
$.each(data.Results, function() {
//my logic here....
$(".loading").bind("ajaxStart", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
});
}
});
return false;
}
My loading indicator doen't seem to showup.. ANy suggestion....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
.ajax()
你应该只调用:
using
.ajax()
you should just call:and
当我们使用 async: false 发送 ajax 调用时,
ajaxStart
和beforeSend
适用于 Firefox,但不适用于所有浏览器(即 Safari)。我还在寻找这个方法ajaxStart
andbeforeSend
does work for Firefox but not for the all browsers (ie Safari) when we are sending the ajax call with async: false. I'm still finding the way for this