简体   繁体   English

加载div进行AJAX调用不会在IE或Chrome中显示,在Firefox中可以正常工作

[英]Loading div for AJAX call doesn't display in IE or Chrome, works fine in Firefox

I'm trying to write a very simple function which displays a div that says "Loading...", then makes a jQuery ajax() call, and once complete, hides the loading div. 我正在尝试编写一个非常简单的函数,该函数显示一个显示“ Loading ...”的div,然后进行jQuery ajax()调用,并在完成后隐藏该加载div。 The code works perfectly in Firefox, but IE 7 (maybe 8/9 as well, tested on 7 only) and Chrome both have issues: 该代码可在Firefox中完美运行,但是IE 7(也许也为8/9,仅在7上进行了测试)和Chrome均存在以下问题:

function ajaxwl(url) {
    $('#loadingDiv').show();
    var xmlHttp=$.ajax({type: "GET",
        url: url,
        async: false });
    $('#loadingDiv').hide();
    return xmlHttp;
}

I stepped through the code with the Chrome debugger, and then it worked - the loading div was displayed as expected. 我使用Chrome调试器逐步浏览了代码,然后工作了-加载div按预期显示。 If I run the code without the debugger, however, Chrome (and IE 7) load the AJAX request without ever showing the loading div. 但是,如果我在没有调试器的情况下运行代码,Chrome(和IE 7)将加载AJAX请求,而不会显示加载div。 Perhaps it has something to do with the fact that Chrome is locking up the browser, as I am using a non-asynchronous request? 也许这与Chrome锁定浏览器有关,因为我正在使用非异步请求?

EDIT: I ended up converting the request to an asynchronous request (a conversion which needed to be done everywhere in this code I inherited, but I had been procrastinating...) and now all works as expected: 编辑:我最终将请求转换为异步请求(这种转换需要在我继承的这段代码中的任何地方进行,但是我一直在拖延...),现在所有工作都按预期进行:

function ajaxwl(url) {
    $('#loadingDiv').show();
    var xmlHttp=$.ajax({type: "GET",
        url: url
    }).done(function() {
        $('#loadingDiv').hide();
    });
    return xmlHttp;
}

Thanks for the quick responses! 感谢您的快速回复!

The loading div is not visible in IE because you are using AJAX in synchronous mode due to which the js execution hangs the browser and you will not see when it is visible and when it gets hidden. 加载div在IE中不可见,因为您在同步模式下使用AJAX,因此js执行会挂起浏览器,并且看不到何时可见和何时隐藏。 In all other browsers the js execution is pretty fast so you can see it. 在所有其他浏览器中,js的执行速度非常快,因此您可以看到它。

i had same problem in IE a while ago. 不久前我在IE中遇到了同样的问题。 Inspecting the problem revealed that html that was returned by ajax request was malformed (missing closing tag etc.) and IE is very unforgiving in such scenarios. 检查问题后发现,ajax请求返回的html格式不正确(缺少结束标记等),在这种情况下IE非常宽容。 Maybe you have the same issue here. 也许您在这里有同样的问题。

暂无
暂无

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

相关问题 此代码可以在ie 10上正常运行,但不能在chrome和firefox上运行(javascript / ajax部分) - this code works fine on ie 10 but not on chrome and firefox (javascript/ajax portion) 下拉菜单不会在Chrome中更新文本字段值,但在Firefox和IE中可以正常工作 - Dropdown Menu doesn't update textfield values in Chrome, but works fine in Firefox and IE 强制仅数字js函数在Firefox中不起作用,但在Chrome和IE中可以正常工作 - Force numeric only js function doesn't work in Firefox but in Chrome & IE works fine Ajax 调用/javascript - 在 IE、Firefox 和 Safari 上运行良好,但在 Chrome 上运行不正常 - Ajax call/javascript - working fine on IE, Firefox and Safari but not on Chrome Ajax呼叫未在firefox中更新DIV。 在Chrome中正常工作 - Ajax Call not updating DIV in firefox. Working fine in Chrome <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF - <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF $ .ajax async:false在IE和Firefox中不起作用,适用于Chrome / Safari - $.ajax async:false doesn't work in IE and Firefox, works in Chrome/Safari 页面在 Firefox 中无法正常工作,但在 chrome 中工作正常 - Page doesn't work as intended in Firefox but works fine in chrome Firefox无法正常播放动画gif(在Chrome中运行正常) - Firefox doesn't play animated gif properly (works fine in Chrome) Google Charts:折线图:不在IE和Firefox中显示,但在Chrome中有效 - Google Charts: Line Chart: Doesn't display in IE and Firefox, but works in chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM