weixin_33737774 2013-12-16 18:35 采纳率: 0%
浏览 24

IE8中的Ajax怪异行为

Here's the code I use to ajax more reviews:

function showMoreReviews(str) {
    var counter = Number($('#counter').val());
    var xmlhttp;
    if (str == "") {
        document.getElementById("reviews").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    counter = counter + 10;
    $('#counter').attr({ value: counter });

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //document.getElementById("reviews").innerHTML = xmlhttp.responseText;
            $("#reviews").append("<div id='rnum" + counter + "'>" + xmlhttp.responseText + "</div>");
            $("#rnum" + counter).hide().fadeIn(800);
        }
    }

    console.log(str);
    console.log(counter);
    xmlhttp.open("GET", "/MoreReviewsAjax.asp?ml=" + str + "&c=" + counter, true);
    xmlhttp.send();
}

It works fine in all browsers except in IE8.. Now here is the weird thing - the code will work if in IE8 I go to dev tools and start debugging for scripts. Otherwise it doesn't work.

PS I am using virtual PC and Windows XP w/ IE8 for IE8 tests.

  • 写回答

1条回答 默认 最新

  • helloxielan 2013-12-16 18:35
    关注

    Your console.log() calls are the problem.

    You can add a cheap "polyfill" to your system:

    if (!('console' in window)) {
      window.console = {
        log: function() {},
        dir: function() {},
        // whatever other console functions you use
      };
    }
    

    Those dummy functions won't do anything, but they'll keep IE from losing it's mind.

    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格