【问题标题】:The following JQuery and Javascript does not work correctly in Internet Explorer 6 onwards以下 JQuery 和 Javascript 在 Internet Explorer 6 及更高版本中无法正常工作
【发布时间】:2012-07-11 08:19:30
【问题描述】:

知道为什么以下代码不会在 IE6 和 8 中不断更新,但在 Chrome 和 FF 中运行良好。

$(document).ready(function () {

        window.setInterval(function () {

            $('div').each(function (index, item) {

                var vm = $(item).text();
                var env = "some url (cant show)";

                $.ajax(env, {
                    URL: env,
                    type: "GET",
                    dataType: "html",
                    success: function (data) {                          
                        var style = $(data).filter('div');
                    $(item).replaceWith(style);

                    },
                    error: function () {
                        $(item).css('background', '#f00');
                    }
                });
            });
        }, 10000);
});

div 将更改一次,然后再也不更改。然而,在 Chrome 和 FF 中,div 每隔 10 秒就会改变一次。

感谢您的帮助!

【问题讨论】:

    标签: jquery ajax internet-explorer html replace


    【解决方案1】:

    尝试编写您的脚本(未测试)...

        $(document).ready(function () {
    
        window.setInterval(function () {
    
            $('div').each(function (index, item) {
    
                var vm = $(item).text();
                var env = "some url (cant show);
    
                $.ajax(env, {
    
                    URL: env,
    
                    type: "GET",
    
                    cache:"false", //NOTICE FALSE!!
    
                    dataType: "html",
    
                    success: function (data) {
    
    
                        var style = $(data).filter('div');
                        $(item).replaceWith(style);
    
                    },
    
                    error: function () {
    
    
    
                        $(item).css('background', '#f00');
    
                    }
    
                });
            });
    
        }, 10000);
    
    });`
    

    【讨论】:

    • 我还必须注意我做了缓存:false,- 不包括双引号。
    • 嗯尝试添加 $.ajaxSetup({ cache: false });在你的 ajax 函数之上。也许它会成功。如果不是不知道你还能做什么:(
    • 也试过了 - 还是不开心!
    • 如果您可以尝试将“GET”更改为“POST”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多