我試圖用一個按鈕點擊通過javascript調用時顯示一個GIF動畫div。但問題是,它只能在Firefox中正常工作。在IE和Chrome中,動畫不會顯示出來。我試着用alert(「stop」)來調試;動畫之前和之後,它確實工作,但我刪除警報後,它不會工作了。有什麼建議嗎?動畫不工作在IE瀏覽器時,jQuery函數內調用js函數
下面是該TestPage.aspx的片段:
<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的片段:
// 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函數
我面臨同樣的問題,如果你得到解決方案,然後幫我解決它。 –