【发布时间】:2012-06-13 11:13:56
【问题描述】:
当通过 javascript 调用单击按钮时,我正在尝试在内部显示带有 gif 动画的 div。但问题是,它只在 Firefox 中运行良好。在 IE 和 Chrome 中,动画不会显示。我试过用 alert("stop");在动画之前和之后,它确实可以工作,但是在我删除警报之后,它就不再工作了。请问有什么建议吗?
这是 TestPage.aspx 的 sn-p:
<div id="animationDiv" style="display: none;">
<img src="loading.gif" />
</div>
...
<div>
<asp:Button ID="testButton" runat="server" Text="Test AJAX" OnClientClick="return testButtonClick();" />
</div>
...
<script type="text/javascript">
<!--
var docWidth, docHeight;
function testButtonClick() {
var o_animationDiv = $("#animationDiv");
o_animationDiv.width(docWidth);
o_animationDiv.height(docHeight);
o_animationDiv.show();
$.ajax({
type: "Post",
url: "TestPage.aspx/TestAjax",
async: false,
cache: false,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: testAjaxSuccess,
error: testAjaxError
});
function testAjaxSuccess(data, status, xhr) {
// do something here
};
function testAjaxError(xhr, status, error) {
// do something here
};
o_animationDiv.hide();
return false;
};
$(document).ready(function () {
docWidth = $(document).width();
docHeight = $(document).height();
});
//-->
</script>
这是 TestPage.aspx.cs 的 sn-p:
// using PageMethod for ajax
[System.Web.Services.WebMethod(EnableSession = true)]
public static string TestAjax()
{
System.Threading.Thread.Sleep(5000); // 5 seconds
// or do something else here
// ie. if validation error, throw an exception
return string.Empty;
}
更新 1:添加了一些 javascript 函数
【问题讨论】:
-
我也遇到了同样的问题,如果你得到了解决方案,那就帮我解决吧。
标签: javascript jquery ajax animation webmethod