简体   繁体   English

显示加载图像效果不佳

[英]Show a loading image is not working well

I have defined the following script as part of implementing paging :- 我已定义以下脚本作为实现分页的一部分:

    var getPage = function () {
        var $a = $(this);
        var options = {
            url: $a.attr("href"),
            data: $("form").serialize(),
            type: "get"
        };
        $.ajax(options).done(function (data) {
            $(".loadingimage").show();
            var target = $a.parents("div.pagedList").attr("data-tms-target");
            $(target).replaceWith(data);
        });
        return false;
    };


$(document).ready(function () {

    $(".main-content").on("click", ".pagedList a", getPage);


})

And part of the mark-up is as follow:- 部分加价如下:-

<div id="AuditTable">
<div class="pagedList" data-tms-target="#AuditTable">
                        @Html.PagedListPager(Model , page => Url.Action("Index",new { page }),
                        PagedListRenderOptions.ClassicPlusFirstAndLast)

</div>  <img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" />
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead><tr>

The paging will work well , but the problem is that the 分页效果很好,但是问题是

$(".loadingimage").show();

Will not show the hidden loading image during data retrieval, can anyone advice on this problem ? 在数据检索期间不会显示隐藏的加载图像,有人可以对此问题提出建议吗?

Try these 试试这些

  • You can load the image in your browser (eg http://yourdomain.com/Content/Ajax-loader-bar.gif ) If you can, consider writing full url as image src. 您可以在浏览器中加载图像(例如, http : //yourdomain.com/Content/Ajax-loader-bar.gif )。如果可以,请考虑将完整URL写入图像src。
  • Try id as selector (eg $("#progress2).show(); ) 尝试使用id作为选择器(例如$("#progress2).show();
  • If those are not leading you to anywhere you can put the image into a div, remove its class (assume that you hide it with css), .show(); 如果这些都不能将您带到可以将图像放入div的任何位置,请删除其类(假设您使用css将其隐藏) .show(); and .hide(); .hide(); within getPage function. 在getPage函数中。

HTML: HTML:

<div id="loadcontainer"><img src="Content/Ajax-loader-bar.gif" id="progress2" /></div>

Javascript: 使用Javascript:

var getPage = function () {
  $("#loadcontainer").show();
  var $a = $(this);
  var options = {
      url: $a.attr("href"),
      data: $("form").serialize(),
      type: "get"
  };
  $.ajax(options).done(function (data) {
      $("#loadcontainer").hide();
      var target = $a.parents("div.pagedList").attr("data-tms-target");
      $(target).replaceWith(data);
  });
  return false;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM