首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么使用ajax,对页面中的javascript控件实时修改

2013-08-09 
如何使用ajax,对页面中的javascript控件实时修改?菜鸟一只,有地方说的不对的请见谅,希望多多指导。要做一个

如何使用ajax,对页面中的javascript控件实时修改?
菜鸟一只,有地方说的不对的请见谅,希望多多指导。
要做一个表格控件 实时显示数据库的数据 简单如下图:(使用jqplot)
怎么使用ajax,对页面中的javascript控件实时修改

这一段展现的是一个javascript代码,对一个DIV进行了修改


<h1>表格展示</h1>
<script class="code" type="text/javascript">
$(document).ready(function(){
    var s1 = [200, 600, 700, 1000];
    var s2 = [460, -210, 690, 820];
    var s3 = [-260, -440, 320, 200];
    // Can specify a custom tick Array.
    // Ticks should match up one for each y value (category) in the series.
    var ticks = ['May', 'June', 'July', 'August'];
     
    var plot1 = $.jqplot('chart', [s1, s2, s3], {
        // The "seriesDefaults" option is an options object that will
        // be applied to all series in the chart.
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions: {fillToZero: true}
        },
        // Custom labels for the series are specified with the "label"
        // option on the series option.  Here a series option object
        // is specified for each series.
        series:[
            {label:'Hotel'},
            {label:'Event Regristration'},
            {label:'Airfare'}
        ],
        // Show the legend and put it outside the grid, but inside the
        // plot container, shrinking the grid to accomodate the legend.
        // A value of "outside" would not shrink the grid and allow


        // the legend to overflow the container.
        legend: {
            show: true,
            placement: 'insideGrid'
        },
        axes: {
            // Use a category axis on the x axis and use our custom ticks.
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            },
            // Pad the y axis just a little so bars can get close to, but
            // not touch, the grid boundaries.  1.2 is the default padding.
            yaxis: {
                pad: 1.05,
                tickOptions: {formatString: '$%d'}
            }
        }
    });
});
</script>
<div id="chart" style="height:400px;width:700px; "></div> 



由上面可以看出,数据是通过其中的一个数组展现的
我想请问,如果我想用ajax(或者别的什么)动态的改变这个表格的数据,应该怎么做? JavaScript Ajax 网页
[解决办法]
你可以把
$(document).ready(后面的代码放到一个自定义函数里面,把数组当成全局变量,ajax得到数据库的新的值后,给数组赋值,然后执行自定义函数 一般就可以实现


[解决办法]
重新导入数据

比如barChartStore.removeAll();
barChartStore.loadData(items);


[解决办法]
我也是刚开始看jqplot 因为公司用到,jqplot文档有介绍两个重绘的方法 replot  redraw  我想应该是需要重绘后再加载数据才行

热点排行