本文介绍了IE 11完全不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码可在除EI11之外的所有浏览器中使用.控制台中没有错误,也没有显示任何地方.最近两天,我一直在Stack Overflow上尝试其他所有已回答的问题,包括缓存中断,添加标头选项等所有问题.不知所措,任何指导将不胜感激,我将根据需要添加任何其他信息.

The following code is working in all browser but EI11. There are no errors in the console or displayed anywhere. I have been on Stack Overflow for the last two day trying all of the other answered questions, anything from cache breaking, adding header option. At a lost here, any guidance would be grateful and i'll add any additional info ass needed.

HTML

<!DOCTYPE html>
 <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>API CAll</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="app.js"></script>
<style>
* {
    box-sizing: border-box;
}

div p{
    width: 100px;
    border: 1px solid green;
    padding: 20px;
    margin: 20px;
}
.row {
    display: flex;
}

.column {
    flex: 50%;
    padding: 10px;
    height: 300px; /* Should be removed. Only for demonstration */
}
</style>
</head>

<body>

   <div id="content" class="row"></div>
 </body>
 </html>

JS

 $( document ).ready(function() {

  var api_url2 = 'https://api.exchangeratesapi.io/latest?base=USD&symbols=TRY,BRL,MXN';

    $.ajax({
        type: 'GET',
        url: api_url2 ,
        dataType: 'json',
        success: function(result){

        const objVal = result.rates;
        var keys = [], k, i, len;

        for (k in objVal) {
            if (objVal.hasOwnProperty(k)) {
                keys.push(k);
            }
        }

        keys.sort();

          len = keys.length;

          for (i = 0; i < len; i++) {
            k = keys[i];
            console.log(k + ':' + objVal[k]);
            let column = $("<div class='column'></div>");

                for (j = 0; j < 3; j++) {
                // TODO: Should you match .row here, or use a specific row?
                $(".row").append(column);
                // Use jQuery to create the P element instead of the DOM.
                let para = $('<p></p>');
                // Use the jQuery text() method to set the content.  (Prevents element
                // injection by server via innerHTML.)
                para.text(`${objVal[k].toFixed(3)} ${k} `);

                // Append this element only to the one div we created this iteration of the
                // outer loop.
                column.append(para);
                }
          }


        }
  })
 });

推荐答案

IE11不支持ES6.也就是说,您需要替换:

IE11 doesn't support ES6. That means, you need to replace:

  • 具有旧的ES5语法'string' + 'string'
  • 的模板文字
  • let/const与var(如@lostero所述,IE11支持let/const,),所以最好避免使用它们.
  • Template literals with old ES5 syntax 'string' + 'string'
  • let/const with var (as @lostero mentioned, let/const are supported in IE11, but not fully), so it is better to avoid them.

或使用ES6 +> ES5编译器,例如 Babel

or use ES6+ > ES5 transpiler like Babel

无论如何,这是IE的代码:

Anyway, here is code for IE:

$( document ).ready(function() {

  var api_url2 = 'https://api.exchangeratesapi.io/latest?base=USD&symbols=TRY,BRL,MXN';

    $.ajax({
        type: 'GET',
        url: api_url2 ,
        dataType: 'json',
        success: function(result){

        const objVal = result.rates;
        var keys = [], k, i, len;

        for (k in objVal) {
            if (objVal.hasOwnProperty(k)) {
                keys.push(k);
            }
        }

        keys.sort();

          len = keys.length;

          for (i = 0; i < len; i++) {
            k = keys[i];
            console.log(k + ':' + objVal[k]);
            var column = $("<div class='column'></div>");

                for (j = 0; j < 3; j++) {
                // TODO: Should you match .row here, or use a specific row?
                $(".row").append(column);
                // Use jQuery to create the P element instead of the DOM.
                var para = $('<p></p>');
                // Use the jQuery text() method to set the content.  (Prevents element
                // injection by server via innerHTML.)
                para.text(objVal[k].toFixed(3) + k );

                // Append this element only to the one div we created this iteration of the
                // outer loop.
                column.append(para);
                }
          }


        }
  })
 });
* {
    box-sizing: border-box;
}

div p{
    width: 100px;
    border: 1px solid green;
    padding: 20px;
    margin: 20px;
}
.row {
    display: flex;
}

.column {
    flex: 50%;
    padding: 10px;
    height: 300px; /* Should be removed. Only for demonstration */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <div id="content" class="row"></div>

实时代码

这篇关于IE 11完全不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:42
查看更多