我在我的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" />
答案 0 :(得分:1)
我使用jQuery函数来显示加载图像gif。以下是一个函数
$(".thumb-img img").one("load", function () {
// do stuff
$(this).removeClass("LoaderImg");
}).each(function () {
$(this).addClass("LoaderImg");
if (this.complete) $(this).load();
});
答案 1 :(得分:0)
Please use jQuery ajax { beforeSend, complete } or other javascript library or framework to implement your desire effect. As is well-known, only depends on asp.net can not deliver your thinking.
Have a nice day!