简体   繁体   English

当 JQUERY ajax async 仅在 IE 中设置为 false 时,覆盖不显示

[英]Overlay does'nt show up when JQUERY ajax async set to false only in IE

An input button invokes javascript on the click event.输入按钮在单击事件上调用 javascript。

<input id="ToolbarStatusSubmitHtmlInputButton" type="button" value="Submit" runat="server"  visible="True" enableviewstate="true" onclick="callfunction()"/>

The onclick 'callfunction' is as follow

callfunction: function() {
        showparentOverlay();
        $.ajax({
            url: url,
            type: "GET",
            async: false,.....

 showparentOverlay: function() {
        $("#parentOverlay").removeClass('hideOverlay').addClass('showOverlay');
    },

The Callfunction does 2 things Callfunction 做了两件事

1) Changes to the DOM element by removing and adding class 1) 通过删除和添加 class 来更改 DOM 元素

2) Makes an Ajax Call It is purposefully made async false, to retrive the value from service and get confirmation from user. 2) 进行 Ajax 调用 故意将其设置为 async false,以从服务中检索值并获得用户的确认。

The issue is only in IE browser where showparentOverlay(transparent div) does'nt show until the ajax service call is completed.该问题仅出现在 IE 浏览器中,其中 showparentOverlay(transparent div) 直到 ajax 服务调用完成后才会显示。

However if the AJAX async is SET true the overlay displays.但是,如果 AJAX async 设置为 true,则覆盖显示。

Can anyone please help me with this issue, where I could display the transparent overlay while the connection to service is made and the async for the service is set - false.谁能帮我解决这个问题,我可以在连接到服务并设置服务的异步时显示透明覆盖 - 错误。

Thanks谢谢

Try this:尝试这个:

 function oninputclick() { document.getElementById("window").style.width = "100%"; $.ajax({ async: false, type: 'POST', dataType: 'html', success: function (result) { // success do something }, complete: function () { // enable this when posting to server //setTimeout(function () { document.getElementById("window").style.width = "0%"; }, 3000); } }); //for test only. use this inside the complete function. setTimeout(function () { document.getElementById("window").style.width = "0%"; }, 3000); }
 .overlay { height: 100%; width: 0; position: fixed; z-index: 9999999; top: 0; left: 0; background-color: rgb(0,0,0); background-color: rgba(0,0,0, 0.9); overflow-x: hidden; transition: 0.5s; }.overlay-content { position: relative; top: 25%; width: 100%; text-align: center; margin-top: 30px; }.overlay a { padding: 8px; text-decoration: none; font-size: 36px; color: #f1f1f1; display: block; transition: 0.3s; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="window" class="overlay"> <div class="overlay-content"> <a href="javascript:void(0)" id="msgText">Loading...</a> </div> </div> <input type="button" value="Submit" runat="server" visible="True" onclick="oninputclick();"/>

I would suggest setting the async option to true and using the success function to load the overlay...我建议将async选项设置为true并使用success的 function 加载覆盖...

$.ajax({
   url: url,
   type: 'GET',
   success: function(data){
      //Show Overlay here
   }
});

This will call the service and upon success will then open your overlay.这将调用该服务,成功后将打开您的叠加层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM