【问题标题】:Show loader untill not get response from server显示加载器,直到没有得到服务器的响应
【发布时间】:2017-05-16 09:00:32
【问题描述】:

我在我的 Asp.Net MVC 项目中使用 HttpHandler,它获取缩略图图像并加载到 <img /> 标记中。该功能根据需要正常工作。

但在服务器给出响应之前,我想显示一些加载图标/消息,以便用户知道该图像仍在加载。

我的代码:

HttpHandler 代码:

var currentResponse = HttpContext.Current.Response;

string URL = "http://localhost:50417/API/GetThumbnail";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                    request.KeepAlive = false;
                    request.ProtocolVersion = HttpVersion.Version10;
                    request.Method = "GET";
                    request.Timeout = 30000;
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    StreamReader streamr = new StreamReader(response.GetResponseStream());


                    currentResponse.Write(streamr.ReadToEnd());

RouteConfig.cs

routes.Add(new Route("Thumbnail/getImage", new ThumbnailImageRouteHandler()));

index.csHtml

<img src="/Thumbnail/getImage" />

【问题讨论】:

    标签: c# asp.net-mvc httphandler


    【解决方案1】:

    我已经使用 jQuery 函数来显示加载图像 gif。下面是一个函数

    $(".thumb-img img").one("load", function () {
            // do stuff
            $(this).removeClass("LoaderImg");
        }).each(function () {
            $(this).addClass("LoaderImg");
            if (this.complete) $(this).load();
        });
    

    【讨论】:

      【解决方案2】:

      请使用 jQuery ajax { beforeSend, complete } 或其他 javascript 库或框架来实现您想要的效果。众所周知,仅仅依靠asp.net是无法传递你的想法的。

      祝你有美好的一天!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多