DataTables jQuery插件 - Firefox声称“非法字符”

时间:2017-03-23 09:17:09

标签: javascript jquery firefox datatables cdn

得到这样的东西:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
    <script>
    $(document).ready(function() {
        $("#myTable").dataTable({
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            "iDisplayLength": 25,
            "order": []
        });
    });
    </script>
    <style>
    th,
    td {
        white-space: nowrap
    }

    TD+TD+TD+TD+TD+TD {
        color: white
    }
    </style>
</head>

<body>
    <table id="myTable" class="display" cellspacing="0" width="100%"> .... </table>
</body>

</html>

这在Internet Explorer 11中运行良好。 Firefox 52将不会加载DataTables插件并声明SyntaxError: illegal character在从CDN加载的jquery.dataTables.min.js的第一个字符上。 还试图保存js文件并在本地加载它,仍然是一样的。 这是怎么回事?

感谢您的帮助!

修改

所以我下载了DataTables CSS和JS文件,并使用编码UTF-8 with BOM重新保存它们。它们之前保存为UTF-8(没有BOM)。现在它正在运作。这是Firefox中的错误吗?我怎么能避免这个?

1 个答案:

答案 0 :(得分:1)

通过以下方式解决了这个问题:

 <script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" charset="utf-8"></script>
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" charset="utf-8">