Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery Ajax加载图像不加载Ajax调用_Jquery_Ajax - Fatal编程技术网

jQuery Ajax加载图像不加载Ajax调用

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

我将下面的jQuery代码片段用于我在许多站点上使用的ajax加载图像,由于某些原因,它在触发ajax请求时不会显示加载图像

jQuery:

$(".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.
        }
    });