Javascript IE8-SCRIPT70中的谷歌图表问题:权限拒绝格式+;en,默认值+;en,ui+;恩,corechart+;en.I.js,第86行,第16个字符

Javascript IE8-SCRIPT70中的谷歌图表问题:权限拒绝格式+;en,默认值+;en,ui+;恩,corechart+;en.I.js,第86行,第16个字符,javascript,ajax,charts,internet-explorer-8,google-visualization,Javascript,Ajax,Charts,Internet Explorer 8,Google Visualization,在IE8中使用谷歌图表时,我有以下错误 SCRIPT70:权限拒绝格式+en,默认+en,ui+en,corechart+en.I.js,第86行字符16 从我的父页面我有drawChart()和全局chartDatas数组变量,从这个页面我通过ajax调用子页面,有chartDatas数组为图表输入成功调用子页面后我调用drawChart()函数用新数组绘制图表,当时在IE8上面,鼠标在页面上方时不断发生错误。因此,它在我的应用中引起了很多问题。以下是在IE8中重现此问题的示例代码(在最新浏览

在IE8中使用谷歌图表时,我有以下错误

SCRIPT70:权限拒绝格式+en,默认+en,ui+en,corechart+en.I.js,第86行字符16

从我的父页面我有drawChart()和全局chartDatas数组变量,从这个页面我通过ajax调用子页面,有chartDatas数组为图表输入成功调用子页面后我调用drawChart()函数用新数组绘制图表,当时在IE8上面,鼠标在页面上方时不断发生错误。因此,它在我的应用中引起了很多问题。以下是在IE8中重现此问题的示例代码(在最新浏览器中,如chrome、firefox、IE10,其工作正常)

parentPage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("visualization", "1", {packages: ["corechart"]});
            google.setOnLoadCallback(drawChart);
            var year = 2008;
            var chartDatas = [
                ['Year', 'Sales', 'Expenses'],
                ['2004', 1000, 400],
                ['2005', 1170, 460],
                ['2006', 660, 1120],
                ['2007', 1030, 540]
            ];
            function drawChart() {
                var data = google.visualization.arrayToDataTable(chartDatas);

                var options = {
                    title: 'Company Performance',
                    vAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
                };

                var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
                chart.draw(data, options);
            }
            function callChild() {
                $.ajax({
                    url: "childJsp.jsp",
                    complete: function(res, textStatus) {
                        $('#childPage').html(res.responseText);                        
                    }
                });
            }
        </script>
    </head>
    <body>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
        <br>
        <input type="button" onclick="callChild();" value="call child page">
        <div id="childPage"> </div>
    </body>
</html>
<script>       
    chartDatas.push([''+(year++), 900, 400]);
    drawChart();
</script>

load(“可视化”、“1”、{packages:[“corechart”]});
setOnLoadCallback(drawChart);
var年=2008年;
var图表数据=[
[“年度”、“销售额”、“费用”],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
];
函数绘图图(){
var data=google.visualization.arrayToDataTable(chartDatas);
变量选项={
标题:“公司业绩”,
变量:{title:'Year',titleTextStyle:{color:'red'}
};
var chart=new google.visualization.BarChart(document.getElementById('chart_div'));
图表绘制(数据、选项);
}
函数callChild(){
$.ajax({
url:“childJsp.jsp”,
完成:功能(res、textStatus){
$('childPage').html(res.responseText);
}
});
}

childJsp.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("visualization", "1", {packages: ["corechart"]});
            google.setOnLoadCallback(drawChart);
            var year = 2008;
            var chartDatas = [
                ['Year', 'Sales', 'Expenses'],
                ['2004', 1000, 400],
                ['2005', 1170, 460],
                ['2006', 660, 1120],
                ['2007', 1030, 540]
            ];
            function drawChart() {
                var data = google.visualization.arrayToDataTable(chartDatas);

                var options = {
                    title: 'Company Performance',
                    vAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
                };

                var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
                chart.draw(data, options);
            }
            function callChild() {
                $.ajax({
                    url: "childJsp.jsp",
                    complete: function(res, textStatus) {
                        $('#childPage').html(res.responseText);                        
                    }
                });
            }
        </script>
    </head>
    <body>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
        <br>
        <input type="button" onclick="callChild();" value="call child page">
        <div id="childPage"> </div>
    </body>
</html>
<script>       
    chartDatas.push([''+(year++), 900, 400]);
    drawChart();
</script>

push([''+(year++),900400]);
图纸();

通过ajax调用加载子页面后,控制台中出现打印错误


我怀疑您需要重新排列代码,以便重用同一个图表对象,而不是反复创建新的图表对象

这可能会奏效:

将您的javascript更改为:

function drawChart() {
    var data = google.visualization.arrayToDataTable(chartDatas);

    var options = {
        title: 'Company Performance',
        vAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
    };

    var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
    chart.draw(data, options);

    function callChild() {
        $.ajax({
            url: "childJsp.jsp",
            complete: function(res, textStatus) {
                $('#childPage').html(res.responseText);
                var data = google.visualization.arrayToDataTable(chartDatas);
                chart.draw(data, options);
            }
        });
    }

    var button = document.querySelector('#callChild');
    if (document.addEventListener) {
        el.addEventListener('click', callChild);
    }
    else {
        el.attachEvent('onclick', callChild);
    }
}
在响应中,删除
callChild
函数调用。在HTML中,将按钮更改为:

<input type="button" id="callChild" value="call child page">

当响应页面在不调用drawChart()函数的情况下绘制图表时,它会起作用。