jQuery Ajax加载图像不加载Ajax调用
我将下面的jQuery代码片段用于我在许多站点上使用的ajax加载图像,由于某些原因,它在触发ajax请求时不会显示加载图像 jQuery:jQuery Ajax加载图像不加载Ajax调用,jquery,ajax,Jquery,Ajax,我将下面的jQuery代码片段用于我在许多站点上使用的ajax加载图像,由于某些原因,它在触发ajax请求时不会显示加载图像 jQuery: $(".loading").hide().ajaxStart(function() { $(this).show(); }).ajaxStop(function() { $(this).hide(); }); 示例Ajax调用(按预期工作并返回正确数据): HTML: HTML代码受到jQuery的影响,因为页面加载时添加了display
$(".loading").hide().ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
示例Ajax调用(按预期工作并返回正确数据):
HTML:
HTML代码受到jQuery的影响,因为页面加载时添加了display:none
,没有错误,如果我通过firebug在HTML上更改display:block
,则会显示loading.gif图像
非常感谢您的帮助。也许可以尝试将其更改为
$(".loading").hide();
$(document).ajaxStart(function() {
$(".loading").show();
}).ajaxStop(function() {
$(".loading").hide();
});
不要将其链接到
$('.loading')
,后者可能不会触发ajaxStart()
事件。也许可以尝试将其更改为
$(".loading").hide();
$(document).ajaxStart(function() {
$(".loading").show();
}).ajaxStop(function() {
$(".loading").hide();
});
不要将其链接到
$('.loading')
,后者可能不会触发ajaxStart()
事件。您可以使用发送前和完成
方法:
$.ajax({
url: "ajax.php",
type: "POST",
data: vData,
beforeSend: function () {
$(".loading").show(); // <----show before sending
},
success: function (data, textStatus, jqXHR) {
$('#itemList').html(data);
},
complete: function () {
$(".loading").hide(); // on complete of ajax hide it.
}
});
$.ajax({
url:“ajax.php”,
类型:“POST”,
数据:vData,
beforeSend:函数(){
$(“.loading”).show();//您可以使用beforeSend
和complete
方法:
$.ajax({
url: "ajax.php",
type: "POST",
data: vData,
beforeSend: function () {
$(".loading").show(); // <----show before sending
},
success: function (data, textStatus, jqXHR) {
$('#itemList').html(data);
},
complete: function () {
$(".loading").hide(); // on complete of ajax hide it.
}
});
$.ajax({
url:“ajax.php”,
类型:“POST”,
数据:vData,
beforeSend:函数(){
$(“.loading”).show();//您读过文档吗:???从jQuery 1.8开始,.ajaxStart()方法应该只附加到文档。@A.Wolff谢谢链接。您读过文档吗:???从jQuery 1.8开始,.ajaxStart()方法应该只附加到文档。@A.Wolff谢谢链接。
$.ajax({
url: "ajax.php",
type: "POST",
data: vData,
beforeSend: function () {
$(".loading").show(); // <----show before sending
},
success: function (data, textStatus, jqXHR) {
$('#itemList').html(data);
},
complete: function () {
$(".loading").hide(); // on complete of ajax hide it.
}
});