servlet中的HTML无法正常工作

时间:2014-08-22 10:25:52

标签: javascript json tomcat7

我确保servlet工作得很好。但是html文件什么都没打印。我正在尝试使用Visualization API打印图表,但屏幕上没有任何内容。甚至没有Document.write语句。

以下是我的代码:

<html>
    <head>
        <script type="text/javascript" src="js/json2.js"></script>
        <script type="text/javascript" src="js/jsonStringify.js"></script>
        <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">

            var queryObject="";
            var queryObjectLen="";
            $.ajax({
                type : 'POST',
                url : 'http://localhost:8080/DBCHART/db',
                dataType:'json',
                success : function(data) {
                    queryObject = eval('(' + JSON.stringify(data) + ')');   
                    queryObjectLen = queryObject.Details.length;
                },
                error : function(xhr, type) {
                    alert('server error occoured')
                }
            });
            var arrdata="";
            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(drawChart);
            function drawChart() {
                arrdata = new google.visualization.DataTable();
                arrdata.addColumn('string', 'DeptName');
                arrdata.addColumn('number', 'NumberOfEmployees');

                for(var i=0; i<queryObjectLen; i++){
                    var dept= queryObject.Details[i].DeptName;
                    document.write(dept);

                    var emp = queryObject.Details[i].NumberOfEmployees;
                    document.write(emp);
                    arrdata.addRows([
                        [dept, parseInt(emp)]
                        document.write(arrdata);
                    ]);
                }
                var options = {
                    title: 'Department vs. Number of Employees'
                };
                var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
                chart.draw(arrdata, options);
            }
        </script>
    </head>
    <body>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
    </body>
</html>

0 个答案:

没有答案