MVC3 Ajax.ActionLink和显示延迟LoadingElementId [英] mvc3 Ajax.ActionLink and delaying LoadingElementId from showing

查看:243
本文介绍了MVC3 Ajax.ActionLink和显示延迟LoadingElementId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进步的div横跨网页顶部的绝对位置。

当我点击一个Ajax.ActionLink,有时我看到它闪烁在顶部时,请求/响应只是短暂瞬间。

我如何添加一个延迟,这样的进步的旗帜不显示为500毫秒?

谢谢

这是工作code

  VAR showProgress = FALSE;
功能AjaxBegin()
{
    showProgress = TRUE;
    的setTimeout(如果(showProgress){$('#进步)显示();},800);

}
功能AjaxComplete()
{
    showProgress = FALSE;
    $(#进步)隐藏()。
}
功能AjaxFailure(ajaxContext)
{
    VAR响应= ajaxContext.responseText;
    警报(错误code [+ ajaxContext.Error code +]+响应);
}
 

AjaxOptions

  InsertionMode = InsertionMode.Replace;
OnFailure =AjaxFailure;
OnBegin =AjaxBegin;
的onComplete =AjaxComplete;
HttpMethod =GET;
 

解决方案

您将需要处理这个自己。

而不是指定一个 AjaxOptions.LoadingElementId 您可以通过指定功能的 OnBegin (表现出来)和的onComplete (隐藏)事件。

请参阅 http://msdn.microsoft.com/en-us/library /dd460351.aspx 关于 AjaxOptions

详细

有创建延迟的几种方法 - 看如何等待5与jQuery秒?

而这里的,做它用jQuery的一个例子 - <一个href="http://stackoverflow.com/questions/1851569/delay-the-showing-of-a-ajax-loading-gif-using-jquery">delay使用jQuery 一个AJAX加载GIF的表现

I have a progress div which absolute positions across the top of the web page.

When I click on a Ajax.ActionLink, sometimes I see it flicker at the top when the request/response is just short of instant.

How can I add a delay so that the progress banner does not show for 500ms?

thank you

Here is the working code

var showProgress = false;
function AjaxBegin()
{
    showProgress = true;
    setTimeout("if (showProgress) { $('#progress').show(); }", 800);

}
function AjaxComplete()
{
    showProgress = false;
    $("#progress").hide();
}
function AjaxFailure(ajaxContext)
{
    var response = ajaxContext.responseText;
    alert("Error Code [" + ajaxContext.ErrorCode + "] " + response);
}

AjaxOptions

InsertionMode = InsertionMode.Replace;
OnFailure = "AjaxFailure";
OnBegin = "AjaxBegin";
OnComplete = "AjaxComplete";
HttpMethod = "GET";

解决方案

You will need to handle this yourself.

Rather than specifying a AjaxOptions.LoadingElementId you can handle the showing/hiding of your loading element by specifying functions for the OnBegin (show it) and OnComplete (hide it) events.

See http://msdn.microsoft.com/en-us/library/dd460351.aspx for more details on AjaxOptions.

There are a few ways of creating the delay - see How to wait 5 seconds with jQuery?

And here's an example that does it with jQuery - delay the showing of a ajax loading gif using jQuery

这篇关于MVC3 Ajax.ActionLink和显示延迟LoadingElementId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆