1

我想使用 ajax 添加多个局部视图,但是在'google.load(...'整个页面变为空白之后,它会清除我所有的 HTML。

我读了一些api做了'document.write(...'的东西,这就是问题所在,但我不知道如何解决它。

任何想法?

这是我的代码:

View1.cshtml

<html>
   <script type="text/javascript" src="https://www.google.com/jsapi"></script>
   ...
   <div id="container"></div>
   <button id="next"> next</button>
   ...
</html>

脚本.js

$('#next').click(function () {
    $.ajax({
        url: myUrl/view2,
        data: { Id: 5},
        dataType: 'html',
        success: function (result) {
            //debugger;
            $(result).appendTo(container);
        },
        beforeSend: function () {
        },
        complete: function () {
        },
        error: function (message, codError) {
            console.log(message, codError);
        },
        async: true
    });
});

View2.cshtml

<div id="chart_div_81"></div>

<script type="text/javascript">
    (function () {
        // Load the Visualization API and the piechart package.
        google.load('visualization', '1.0', { 'packages': ['corechart'] });

        // Set a callback to run when the Google Visualization API is loaded.
        google.setOnLoadCallback(drawChart);
        // Callback that creates and populates a data table, instantiates the pie chart, passes in the data and draws it.
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['One', 'Two', 'Three'],
                [/10/09/2013',
                        0,
                        15
                    ],
                    ['18/09/2013',
                        0,
                        15
                    ]
            ]);

            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.LineChart(document.getElementById('chart_div_81'));
            chart.draw(data, options); 
        }
    })();
</script>
4

0 回答 0